HttpClient的Post请求

public static String postHttp(String url,String key,String menu){

        try {
            HttpClient hc=new DefaultHttpClient();
            HttpPost gp=new HttpPost(url);

            List<NameValuePair> parameters=new ArrayList<NameValuePair>();
            BasicNameValuePair b=new BasicNameValuePair("key", key);
            BasicNameValuePair b2=new BasicNameValuePair("menu", menu);

            parameters.add(b);
            parameters.add(b2);
            UrlEncodedFormEntity entity=new UrlEncodedFormEntity(parameters, "UTF-8");
            gp.setEntity(entity);

            HttpResponse execute = hc.execute(gp);
            int code = execute.getStatusLine().getStatusCode();
            if(code == HttpStatus.SC_OK){
                HttpEntity httpEntity = execute.getEntity();
                httpToString = EntityUtils.toString(httpEntity, "UTF-8");
            }

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return httpToString;
    }
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/baidu_35124863/article/details/51547317
个人分类: Android
上一篇自定义ImageLoader
下一篇简易百度定位
想对作者说点什么? 我来说一句

HttpClient请求之基础

2016年07月12日 3.94MB 下载

没有更多推荐了,返回首页

关闭
关闭