简体   繁体   English

如何将URL请求作为“引荐来源”发送

[英]How to send a URL request as 'Referer'

I have an app which existed as an iPhone app first and now as an Android app. 我有一个应用程序,该应用程序最初作为iPhone应用程序存在,现在作为Android应用程序存在。 One of the functions is to load a web page which bypasses the security login by passing a string as Referer. 功能之一是加载网页,该网页通过将字符串作为Referer传递来绕过安全性登录。 The code for the iPhone is as follows - iPhone的代码如下-

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 - 我在Android应用中使用的代码是-

 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'. 但是,当我运行它时,访问被拒绝,因为我没有以“ Referer”的身份发送请求。 How can I do that in my Android code? 如何在Android代码中做到这一点?

Use loadUrl() with additionalHttpHeaders parameter. 使用使用loadURL()additionalHttpHeaders参数。 It is available since Android 2.2. 自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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM