Android BufferedReader 被重定向
我需要使用 BufferedReader 读取网页。当我在计算机上将代码片段作为 Java 应用程序运行时,它工作正常。但是,当我在手机上运行代码时,BufferedReader 被重定向到错误的网页。如何阻止 BufferedReader 被重定向?
我尝试访问的页面是 YouTube 帐户的订阅者。我可以在电脑上正常查看该页面,但在手机上却看不到。
I need to read in a webpage using a BufferedReader. When I run the code snippet as a Java application on my computer it works fine. However when I run the code on the phone, the BufferedReader is redirected to the wrong webpage. How can I stop the BufferedReader from being redirected?
The page I am trying to visit is a youtube account's subscribers. I can view the page on my computer just fine, but not on my phone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于Web服务器可以通过使用“用户代理字符串”来识别用于请求页面的浏览器/平台,因此您必须在从java文件下载网页之前更改jdk的用户代理。你应该将这一行添加到你的java程序中:
你可以在这里找到很多用户代理字符串。选择与移动平台无关的一个,例如:
问候,
史蒂芬
As a web server can identify the browser / platform used to request a page by using the "user agent string", you must change the user agent of the jdk before downloading the web page from your java file. You should add this line to your java program :
you acn find a lot of user agent strings here. Pick one that is not associated to a mobile platform like :
Regards,
Stéphane