我为一些httpclinet
编写了代码因为我的服务器只允许两个链接动作而很容易堵塞
必须通过替换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();
}
}
}
需要补充其他相关信息,请通知我