HttpPost 传参数中文乱码

 1 client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000000);
 2         client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 1000000);
 3         HttpPost post = new HttpPost(url);
 4         NameValuePair rq = new BasicNameValuePair("rq", requestObj.toString());
 5         BasicNameValuePair data_type = new BasicNameValuePair("type", req_type);
 6         NameValuePair sid = new BasicNameValuePair("sid", "web123");
 7         List<NameValuePair> list = new ArrayList<NameValuePair>();
 8         list.add(rq);
 9         list.add(sid);
10         list.add(data_type);
11         StringEntity entity = new UrlEncodedFormEntity(list, HTTP.UTF_8);
12         post.setEntity(entity);
13         HttpResponse res = client.execute(post);
14         String respStr = EntityUtils.toString(res.getEntity(),HTTP.UTF_8);
15         this.inputStream = new ByteArrayInputStream(respStr.toString().getBytes("utf-8"));
16         return SUCCESS;


在服务端接收到requestObj.toString()中文乱码 可用在创建Entity时指定编码  StringEntity entity = new UrlEncodedFormEntity(list, HTTP.UTF_8);

在返回的数据中也出现了中文乱码 可使用EntityUtils.toString指定字符编码     String respStr = EntityUtils.toString(res.getEntity(),HTTP.UTF_8);

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。