如何在URL发送引用者请求一个web视图 [英] How to send a referer request in a url for a webView

查看:158
本文介绍了如何在URL发送引用者请求一个web视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示一个网页在我的Andr​​oid应用程序,它正在寻找一个引用者绕过安全性。我是新来的Andr​​oid,所以我知道如何显示网页中的Web视图但不知道如何发送引荐以及URL请求。我敢肯定,这将需要更新HTTPHeaderField,但我找不到它的任何Android的参考。在code以下是我用什么来打开网页,但没有引荐它说:访问被拒绝

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级别的你需要的的Funktion?

For which API-level do you need that funktion?

由于API级别8有一个第二个使用loadURL功能:

Since API Level 8 there is an second loadUrl-function:

  public void loadUrl (String url, Map<String, String> extraHeaders)

随着 extraHeaders ,你应该能够发送引用者。

With the extraHeaders you should be able to send an referer.


编辑:

下面是一个完整的工作的例子

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);

这篇关于如何在URL发送引用者请求一个web视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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