如何发送URL请求为“引用站点”站点、URL

2023-09-07 16:05:39 作者:心不動則不痛

我有一个存在了作为一个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我用我的Andr​​oid应用程序是 -

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

然而,当我运行它的访问因为我不发送该请求是引用站点拒绝。我怎样才能做到这一点在我的Andr​​oid 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);