Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
458 views
in Technique[技术] by (71.8m points)

android - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...