I have problem: on Android 2 the code below works fine, but on Android 4 doesn't work...
try {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 15000);
HttpClient client = new DefaultHttpClient(params);
String postURL = "http://web.lt/data.php";
HttpPost post = new HttpPost(postURL);
List<NameValuePair> paramss = new ArrayList<NameValuePair>();
paramss.add(new BasicNameValuePair("X", "k"));
paramss.add(new BasicNameValuePair("Y", "x"));
paramss.add(new BasicNameValuePair("speed", "xyz"));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(paramss,HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
if (resEntity != null) {
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
}
I tried to download https://code.google.com/p/httpclientandroidlib/ and install right-click on project -> Properties -> Java Build Path -> Libraries -> Add External JARs but when I change:
inport org.apache.http
to
import ch.boye.httpclientandroidlib.HttpEntity;
... the apps crashes.