Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a referer request in a url for a webView

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

I think the answer may lie in the WebView.LoadURL method which adds extra headers but I can't find any examples of it.

like image 368
user616076 Avatar asked Mar 17 '11 16:03

user616076


1 Answers

For which API-level do you need that function?

Since API Level 8 there is a second loadUrl function:

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

With the extraHeaders you should be able to send a referrer.


EDIT:

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);
like image 154
MacGucky Avatar answered Sep 21 '22 21:09

MacGucky