求帮助 用httpclient的下载网页乱码?

hql27 2012-07-28 01:11:50
如题


HttpClient httpClient = new DefaultHttpClient();

HttpResponse response ;
HttpGet get =new HttpGet("http://www.8684.cn/");
try {
response = httpClient.execute(get);
HttpEntity entity = response.getEntity();
System.out.println(EntityUtils.toString(entity));
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


...全文
136 4 打赏 收藏 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hql27 2012-07-29
  • 打赏
  • 举报
回复
好吧,给分共享[Quote=引用 3 楼 的回复:]

我这还有两个类似。
但是是基于javase API的来读取网信息的
如果楼主给分就共享下。。哈哈
[/Quote]
达达KZT 2012-07-28
  • 打赏
  • 举报
回复
我这还有两个类似。
但是是基于javase API的来读取网信息的
如果楼主给分就共享下。。哈哈
达达KZT 2012-07-28
  • 打赏
  • 举报
回复

HttpClient httpClient = new DefaultHttpClient();

HttpResponse response = null;
HttpGet get =new HttpGet("http://www.8684.cn/");

try {
response = httpClient.execute(get);
HttpEntity entity = response.getEntity();

BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
String temp = null;
while( (temp = br.readLine())!=null ){
System.out.println(temp);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


直接运行无乱码
使用BufferedReader来避免乱码
还有就是楼主记得给分啊。
哈哈哈哈哈哈哈。。。
宅宅~ 2012-07-28
  • 打赏
  • 举报
回复
在网页输出内容中:进行转码:
例如:
str1="akghdkjhasgi";
String str=new String(str1.getBytes("ISO-8859-1"),"GBK")
对于“iso-8859-1”和gbk
你可以换编码。。一个一个换
utf-8还有就是gb2312
你自己配。
各种组合。。。就可以了。我就是这样解决的!

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧