How to send a referer request in a url for a webView(如何在 webView 的 url 中发送引用请求)
问题描述
我需要在我的 Android 应用程序中显示一个网页,该网页正在寻找引用者以绕过安全性.我是 Android 新手,所以我知道如何在 Web 视图中显示网页,但不知道如何将引荐来源"与 url 请求一起发送.我确定它需要更新 HTTPHeaderField 但我在 Android 中找不到任何参考.下面的代码是我用来调出网页的代码,但没有引用者",它会显示拒绝访问"
I need to display a web page in my Android app which is looking for a referer to bypass the security. I'm new to Android so I know how to display the web page in a web view but not how to send the 'referer' along with the url request. I'm sure it will need to update the HTTPHeaderField but I cannot find any reference for it in Android. The code below is what I'm using to bring up the web page but without the 'referer' it says 'Access Denied'
WebView webview = new WebView(this);
setContentView(webview);
webview.loadUrl("http://www.mywebsite.com");
我认为答案可能在于添加额外标题的 WebView.LoadURL 方法,但我找不到任何示例.
I think the answer may lie in the WebView.LoadURL method which adds extra headers but I can't find any examples of it.
推荐答案
对于哪个 API 级别需要该函数?
For which API-level do you need that function?
从 API Level 8 开始,有第二个 loadUrl 函数:
Since API Level 8 there is a second loadUrl function:
public void loadUrl (String url, Map<String, String> extraHeaders)
使用 extraHeaders 您应该能够发送推荐人.
With the extraHeaders you should be able to send a referrer.
这是一个完整的工作示例:
Here is a complete working example:
String url = "http://www.targetserver.tld/";
Map<String, String> extraHeaders = new HashMap<String, String>();
extraHeaders.put("Referer", "http://www.referer.tld/login.html");
WebView wv;
wv = (WebView) findViewById(R.id.webview);
wv.loadUrl(url, extraHeaders);
这篇关于如何在 webView 的 url 中发送引用请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 webView 的 url 中发送引用请求
基础教程推荐
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
