该片段如何在httpclient中使用Activity

时间:2012-12-06 09:17:48

标签: android android-fragments httpclient

我为一些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();
        }

    }


}

需要补充其他相关信息,请通知我

0 个答案:

没有答案
相关问题