在用到HttpClient的基本请求和响应时候,发现默认的编码是“
ISO-8859-1
”,这样就存在中文乱码问题了,解决办法如下,记录一下:
http://hc.apache.org/httpclient-3.x/charencodings.html#Request_Response_Body
三种形式:
postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,
"
UTF-8
"
);
postMethod.addRequestHeader(
"
Content-Type
"
,
"
text/html;charset=UTF-8
"
);
postMethod.setRequestHeader(
"
Content-Type
"
,
"
text/html;charset=UTF-8
"
);
http://hc.apache.org/httpclient-3.x/charencodings.html#Request_Response_Body
三种形式:
![](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)