HttpClient post提交数据,汉字转码

Posted shihaiming

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HttpClient post提交数据,汉字转码相关的知识,希望对你有一定的参考价值。

 

 

 

public static String post(String url, String data) throws ClientProtocolException, IOException {
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        //设置请求和传输超时时间
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(60000).build();
        httpPost.setConfig(requestConfig);
        httpPost.setHeader("Content-Type","application/json; charset=utf-8");
        httpPost.setEntity(new StringEntity(data.toString(), Charset.forName("UTF-8")));
        HttpResponse response = httpClient.execute(httpPost);
        String httpEntityContent = getHttpEntityContent(response);
        httpPost.abort();
        return httpEntityContent;
    }

 

以上是关于HttpClient post提交数据,汉字转码的主要内容,如果未能解决你的问题,请参考以下文章

使用异步httpclient框架做get,post提交数据

HttpClient使用post方法提交数据后服务端如何获得这些参数

HttpClient POST/SET方法

Java模拟POST表单提交HttpClient操作

HttpClient实现POST参数提交

如何通过HttpClient去POST一个multipart/form-data数据