在用到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");
时间: 2024-09-16 14:34:37