HttpClient POST的中文编码问题

HttpClient POST的中文编码问题


在用到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 " );

 

转自忆风

你可能感兴趣的:(httpclient,中文,编码,post)