How to send a URL request as 'Referer'

醉酒当歌 提交于 2019-12-02 01:44:04

问题


I have an app which existed as an iPhone app first and now as an Android app. One of the functions is to load a web page which bypasses the security login by passing a string as Referer. The code for the iPhone is as follows -

NSMutableURLRequest *request = [NSMutableURLRequest new];
[request setValue:@"http://myweb.com/" forHTTPHeaderField:@"referer"];
[request setURL:[NSURL URLWithString:@"http://www.theirweb.com/meetings/meetings.plx?CID=TEST2012&O=Generic&Key=4s6p2wz9"]];

[htmlDoc loadRequest:request];

The code I'm using in my Android app is -

 WebView webview = new WebView(this);
 setContentView(webview);

 webview.loadUrl("http://www.theirweb.com/meetings/meetings.plx?CID=TEST2012&O=Generic&Key=4s6p2wz9");  

However, when I run it access is denied as I'm not sending the request as 'Referer'. How can I do that in my Android code?


回答1:


Use loadUrl() with additionalHttpHeaders parameter. It is available since Android 2.2.

Map<String, String> extraHeaders = new HashMap<String, String>();
extraHeaders.put("Referer", "http://www.example.com");

WebView wv = (WebView) findViewById(R.id.webview);
wv.loadUrl("http://google.com", extraHeaders);


来源:https://stackoverflow.com/questions/9903496/how-to-send-a-url-request-as-referer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!