我有问题:在 Android 2 上,下面的代码可以正常工作,但在 Android 4 上不起作用...
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();
}
我尝试下载https://code.google.com/p/httpclientandroidlib/并安装右键单击项目 -> 属性 -> Java 构建路径 -> 库 -> 添加外部 JAR,但是当我更改时:
inport org.apache.http
至
import ch.boye.httpclientandroidlib.HttpEntity;
...应用程序崩溃。