我遇到问题:在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/并安装 右键单击项目 - &gt;属性 - &gt; Java构建路径 - &gt;图书馆 - &gt;添加外部JAR 但是当我改变时:
inport org.apache.http
到
import ch.boye.httpclientandroidlib.HttpEntity;
......应用程序崩溃。