我需要了解如何使用 URLConnection 对象来充当 WebView
我正在使用 URLConnection 连接到网站并发送 POST 请求,但收到错误页面响应,因为它无法检测到我的浏览器。如何向页面发送我的用户代理字符串和它需要的其他部分?
我知道只有当它无法检测到正在使用的浏览器或检测到与该网站不兼容的浏览器时才会出现我收到的错误。我在同一应用程序上创建了一个 WebView 并使用它成功登录到该站点。我使用内置浏览器并成功登录该网站。
这是在 Android 手机 SDK 2.3.3 Level 10 上开发的。
请在此处回复以回答或询问有关该问题的任何问题。 约书亚。
I am using a URLConnection to connect to a website and send a POST request but I get an error page response because it can't detect my browser. How can I send the page my user agent string and other pieces it needs?
I know the error I get is only given when it can't detect the browser being used or detects one that isn't compatible with the site. I have created a WebView on the same application and used it to successfully log into the site. I used the built in browser and successfully logged into the site.
This is being developed on an Android phone SDK 2.3.3 Level 10.
Please reply here to answer or ask any questions about the problem.
Joshua.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看您要模拟的浏览器发送的 http 标头并设置您的 URLConnection,使其看起来相似。
使用它来帮助做到这一点:
http://developer.android.com/reference/java/net/HttpURLConnection.html
Look at the http header that the browser that you want to emulate is sending and set up your URLConnection so that it will look similar.
Use this for assistance on doing that:
http://developer.android.com/reference/java/net/HttpURLConnection.html