详解Android Webview加载网页时发送HTTP头信息
作者:lqh 时间:2023-11-16 02:32:34
详解Android Webview加载网页时发送HTTP头信息
当你点击一个超链接进行跳转时,WebView会自动将当前地址作为Referer(引荐)发给服务器,因此很多服务器端程序通过是否包含referer来控制盗链,所以有些时候,直接输入一个网络地址,可能有问题,那么怎么解决盗链控制问题呢,其实在webview加载时加入一个referer就可以了,如何添加呢?
从Android 2.2 (也就是API 8)开始,WebView新增加了一个接口方法,就是为了便于我们加载网页时又想发送其他的HTTP头信息的。
以下是一个简单的demo,来展示以下如何使用。
public void testLoadURLWithHTTPHeaders() {
final String url = "http://droidyue.com";
WebView webView = new WebView(getActivity());
Map<String,String> extraHeaders = new HashMap<String, String>();
extraHeaders.put("Referer", "http://www.google.com");
webView.loadUrl(url, extraHeaders);
}
同样上面也可以应用到UserAgent等其他HTTP头信息
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
来源:http://blog.csdn.net/androidyue/article/details/37722815
标签:Android,Webview,HTTP头信息
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android EditText自定义样式的方法
2021-10-06 22:37:37
![](https://img.aspxhome.com/file/2023/0/117060_0s.jpg)
C#将html table 导出成excel实例
2023-12-20 04:58:55
iOS实现从背景图中取色的代码
2023-07-06 15:18:32
Spring Boot日志技术logback原理及配置解析
2022-09-14 10:51:57
![](https://img.aspxhome.com/file/2023/2/63422_0s.png)
Android中EditText屏蔽第三方输入法表情的方法示例
2021-07-23 01:13:11
Android开发使用HttpURLConnection进行网络编程详解【附源码下载】
2022-01-11 23:27:37
Java命令设计模式详解
2022-07-14 04:38:31
android开发设计模式之——单例模式详解
2023-08-31 18:36:42
聊聊Unity 自定义日志保存的问题
2021-11-28 15:38:55
![](https://img.aspxhome.com/file/2023/9/69199_0s.png)
三道java新手入门面试题,通往自由的道路--锁+Volatile
2023-09-04 20:33:42
![](https://img.aspxhome.com/file/2023/7/68717_0s.jpg)
SpringBoot之logback-spring.xml不生效的解决方法
2023-12-05 12:58:11
![](https://img.aspxhome.com/file/2023/0/128930_0s.png)
小白2分钟学会Visual Studio如何将引用包打包到NuGet上
2022-01-14 10:25:53
![](https://img.aspxhome.com/file/2023/9/70439_0s.jpg)
java实现简易飞机大战
2022-08-27 12:36:07
![](https://img.aspxhome.com/file/2023/7/81227_0s.jpg)
Java微信公众平台开发(13) 微信JSSDK中Config配置
2022-12-29 15:58:24
![](https://img.aspxhome.com/file/2023/9/67439_0s.jpg)
解析Android截取手机屏幕两种实现方案
2023-12-16 21:28:06
Java接口继承和使用接口操作示例
2023-11-29 05:08:43
Android中实现TCP和UDP传输实例
2021-11-08 14:19:59
![](https://img.aspxhome.com/file/2023/4/114294_0s.png)
Spring深入刨析声明式事务
2022-07-04 03:57:15
Android开发中如何去掉app标题栏的实现
2023-07-25 00:38:27
![](https://img.aspxhome.com/file/2023/8/137648_0s.jpg)
spring boot下 500 404 错误页面处理的方法
2021-09-03 07:12:36