在用到HttpClient的基本請(qǐng)求和響應(yīng)時(shí)候,發(fā)現(xiàn)默認(rèn)的編碼是“ISO-8859-1”,這樣就存在中文亂碼問(wèn)題了,解決辦法如下,記錄一下: http://hc./httpclient-3.x/charencodings.html#Request_Response_Body 三種形式: ![]() ![]() ![]() 評(píng)論:
# re: HttpClient POST的中文編碼問(wèn)題
2009-06-05 17:35 | okhaoba 我的方法:
HttpClient client = new HttpClient(); //設(shè)置超時(shí)時(shí)間 client.getHttpConnectionManager().getParams().setSoTimeout(timeOut); //使用post方式,參數(shù)長(zhǎng)度不受限制 //postMethod = new PostMethod(url); postMethod = new UTF8PostMethod(url); //設(shè)置參數(shù) NameValuePair[] nameValue = new NameValuePair[] { new NameValuePair("××param", xmlParamStr) }; postMethod.setRequestBody(nameValue); //發(fā)送請(qǐng)求 state = client.executeMethod(postMethod); private static class UTF8PostMethod extends PostMethod { public UTF8PostMethod(String url) { super(url); } @Override public String getRequestCharSet() { //return super.getRequestCharSet(); return "UTF-8"; } } |
|
來(lái)自: 風(fēng)_宇星 > 《CXF》