`
jiangzhenghua
  • 浏览: 592406 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

httpClient请求时乱码问题的解决

    博客分类:
  • web
 
阅读更多
当你使用httpClient发送一个请求时,如果你的请求连接中有含有中文的参数,需要对参数进行特殊的处理,示例代码如下:
String ssoUrl = "http://"+ipport+"/mp/sendMessage?input="+certificate+"&fromUid="+fromUid+"&toUid="+toUid;
String response="";
HttpClient httpClient = new HttpClient();
httpClient.getParams().setBooleanParameter("http.protocol.expect-continue", false);
System.out.println("ssoUrl"+ssoUrl);
String responseValue;
PostMethod getMethod = new UTF8PostMethod(ssoUrl);
NameValuePair[] data = {
                 new NameValuePair("title", title),new NameValuePair("msg", msg)         };
getMethod.setRequestBody(data);
getMethod.addRequestHeader("Connection", "close");  
responseValue = executeRequest(httpClient, getMethod);
正如大家所看到的红色字体部分为含有中文的参数,应该使用如下方式进行提交否则,在服务器端就会出现乱码。
0
2
分享到:
评论
1 楼 mercyblitz 2010-07-07  
如果服务器解析不是UTF-8,照样出问题。

相关推荐

Global site tag (gtag.js) - Google Analytics