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提交数据,汉字转码的主要内容,如果未能解决你的问题,请参考以下文章