关于User-Agent ,关于XML解析!在线等~~~

Mr_Su 2011-05-09 03:47:25
我有2个设备,访问同一个URL,但是返回的结果却不同,我怎么才能保持一致?

我感觉是User-Agent 导致的这个返回结果不同!

于是我尝试修改User-Agent


URLConnection con = url.openConnection();
con.setConnectTimeout(25 * 1000);
//我想骗过服务器,让服务器觉得设备是通过电脑的方式访问
con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");


但是依然没解决。。。

希望大家多提提建议 因为我现在毫无思路~
...全文
713 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
waiwaityu 2011-08-31
  • 打赏
  • 举报
回复
mark。 单词写错了
「已注销」 2011-08-31
  • 打赏
  • 举报
回复
mark。 单词写错了
「已注销」 2011-08-31
  • 打赏
  • 举报
回复
make 。 1楼是亮点
glint 2011-05-09
  • 打赏
  • 举报
回复
如果真是User-Agent导致的不同,应该去查查服务器端的代码
ameyume 2011-05-09
  • 打赏
  • 举报
回复
#     //根据url,取得文字  
private static String getImageText(String url);{
try {
URL u=new URL(url);;
URLConnection uc=u.openConnection();;

//要做足功夫,不然豆瓣就会拒绝你的请求
uc.setRequestProperty("Host","www.douban.com");;
uc.setRequestProperty("Accept","*/*");;
uc.setRequestProperty("Referer","http://www.douban.com/");;
uc.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 5.00; Windows 98);");;
uc.setRequestProperty("Pragma","no-cache");;
uc.setRequestProperty("Cache-Control","no-cache");;
uc.setRequestProperty("Connection","close");;

//StreamUtils是一个辅助工具,就不再给出了
return new String(StreamUtils.read(uc.getInputStream(););,"utf-8");;
} catch (Exception e); {
return "";
}
}

setRequestProperty设置的全面一些,参考:http://www.iteye.com/topic/17023

80,362

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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