我为一些 httpclinet 编写了代码
由于我的服务器只允许两个链接操作,因此很容易堵塞
必须通过replace HttpClient HttpClient链接断开
可以在同一个Activity中简单替换
但是更改完成了如何共享相同 HttpClient 链接的片段
实现替换功能以完成断开连接的要求
HttpClient httpclient = new DefaultHttpClient();
//Regardless of the implementation of several actions are repeated replace
private void JS() {
HttpPost httppost=new HttpPost("IP");
List<NameValuePair> params=new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("s1","2"));
try {
httppost.setEntity(new UrlEncodedFormEntity(params,HTTP.ISO_8859_1));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (ClientProtocolException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
if(response.getStatusLine().getStatusCode()==200){
try {
String strResult=EntityUtils.toString(response.getEntity());
} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
需要补充这方面的其他信息,请通知我