httpClient请求时乱码问题的解决

当你使用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);
正如大家所看到的红色字体部分为含有中文的参数,应该使用如下方式进行提交否则,在服务器端就会出现乱码。

你可能感兴趣的:(httpclient)