如何在 webView 的 url 中发送引用请求 [英] How to send a referer request in a url for a webView

查看:34
本文介绍了如何在 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 中发送引用请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆