Issue
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?
Solution
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);
Answered By - Mariusz Jamro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.