页面返回response里没设置charset,meta里设置了charset=gbk,获取页面出现中文乱码
,httpclient4.0要怎么设置编码啊?网上资料比较少
DefaultHttpClient client = new DefaultHttpClient();
client.getParams().setParameter(HttpProtocolParams.HTTP_CONTENT_CHARSET,"GBK");
以上设置没有用?
代码:
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpget = new HttpGet(
"http://www.ningdaren.com/");
HttpResponse response = client.execute(httpget);
HttpEntity entity = response.getEntity();
System.out.println("登陆前页面返回状态信息----------:");
System.out.println(response.getStatusLine());
Header[] headers = response.getAllHeaders(); // 返回的HTTP头信息
for (int i = 0; i < headers.length; i++) {
System.out.println(headers[i]);
}
//返回页面信息
if(entity!= null){
String responseString = new String(EntityUtils.toString(entity).getBytes("gbk"));
System.out.println(responseString);
}
System.out.println("----------------------------------------");
if (entity != null) {
entity.consumeContent();
}
[b]问题补充:[/b]
具体要怎么设置啊,我试了很多函数都没用。。
httpget.addHeader("Content-Type","application/x-www-form-urlencoded; charset="utf-8")没用啊