问题描述
我需要在我的 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 中发送引用请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)