I am trying to send an HTTP / HTTPS send request from my Android client.
Question
Why is my code not working?
Until
I made a call to the apache / HttpClient class. Everything worked perfectly:
HttpClient httpClient = new DefaultHttpClient();
I read that this method is deprecated, so I switched to the new recommended method:
HttpClient httpClient = HttpClientBuilder.create().build();
Eclipse did not have this class, so I had to download Apache HttpClient 4.3.3. I imported it into my project by copying it to the libs folder and adding to my build path (imported httpclient, httpclient-cache, httpcore, httpmime, fluent-hc, commons-logging, commons-codec).
Error message
06-05 02:15:26.946: W/dalvikvm(29587): Link of class 'Lorg/apache/http/impl/conn/PoolingHttpClientConnectionManager;' failed 06-05 02:15:26.946: E/dalvikvm(29587): Could not find class 'org.apache.http.impl.conn.PoolingHttpClientConnectionManager', referenced from method org.apache.http.impl.client.HttpClientBuilder.build
Latest code
static private String insertJson(String json,String url){ HttpClient httpClient = HttpClientBuilder.create().build(); String responseString = ""; try { HttpPost request = new HttpPost(url); StringEntity params =new StringEntity(json, "UTF-8"); request.addHeader("content-type", "application/json"); request.setEntity(params); HttpResponse response = httpClient.execute(request); HttpEntity entity = response.getEntity(); responseString = EntityUtils.toString(entity, "UTF-8"); }catch (Exception ex) { ex.printStackTrace();
Jjang source share