Jsoup 403 错误和 Android 用户代理

发布于 2024-12-20 12:00:58 字数 898 浏览 3 评论 0原文

我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤芳又自赏 2024-12-27 12:00:58

您的请求很可能被您的移动数据运营商阻止(他们只允许移动用户代理)。

Your request is most likely getting blocked by your mobile data carrier (they only allow mobile User-Agents).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文