Jsoup 403 错误和 Android 用户代理
我想在 Android 应用程序中使用 Jsoup 解析外部网页。实际上我设法做到了,除了它是移动版本。所以...我尝试将用户代理设置为“移动”代理之外的其他内容。
问题是使用 .userAgent() 选项和 .header() 时,IOException 返回 403 错误。
Document doc = Jsoup.connect(url).header("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2").get();
还有 Http 响应:
Date Mon, 12 Dec 2011 04:08:38 GMT
Content-Type text/html; charset=utf-8
Transfer-Encoding chunked
Connection keep-alive
P3P CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires Mon, 12 Dec 2011 00:00:00 GMT
Last-Modified Mon, 12 Dec 2011 04:08:38 GMT
Pragma no-cache
X-Content-Type-Options nosniff
X-XSS-Protection 1; mode=block
Content-Encoding gzip
这里是否有什么东西阻止了连接?
谢谢
I want to parse an external webpage with Jsoup in an android app. Actually I manage to do it except it's the mobile version. So... I tried to set User Agent to something else than a "mobile" one.
The problem is that with .userAgent() option and .header(), IOException returns 403 error.
Document doc = Jsoup.connect(url).header("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2").get();
And the Http Response :
Date Mon, 12 Dec 2011 04:08:38 GMT
Content-Type text/html; charset=utf-8
Transfer-Encoding chunked
Connection keep-alive
P3P CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires Mon, 12 Dec 2011 00:00:00 GMT
Last-Modified Mon, 12 Dec 2011 04:08:38 GMT
Pragma no-cache
X-Content-Type-Options nosniff
X-XSS-Protection 1; mode=block
Content-Encoding gzip
Is there something here preventing the connection ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的请求很可能被您的移动数据运营商阻止(他们只允许移动用户代理)。
Your request is most likely getting blocked by your mobile data carrier (they only allow mobile User-Agents).