问题描述
我有一个存在了作为一个iPhone应用程序的第一,现在作为一个Android应用程序的应用程序。其中一个功能是加载一个网页,它通过传递一个字符串作为Referer的绕过安全登录。在code为iPhone如下 -
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];
在code我用我的Android应用程序是 -
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");
然而,当我运行它的访问因为我不发送该请求是引用站点拒绝。我怎样才能做到这一点在我的Android code?
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?
推荐答案
使用使用loadURL()与 additionalHttpHeaders
参数。这是由于Android 2.2可用。
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);
这篇关于如何发送URL请求为“引用站点”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!