android - 在android webiew中向请求添加标头
问题描述
我有一个必须在 Web 视图中加载的 url,但我需要将标头传递给请求。
我尝试使用 HashMap 将标题设置为 Web 视图,但没有奏效。
我找到了诸如 web 视图拦截客户端之类的解决方案,但没有得到如何加载 url 的正确示例。任何人都可以建议如何实现它。
解决方案
尝试
loadUrl(String url, Map<String, String> extraHeaders)
要向资源加载请求添加标头,请自定义 WebViewClient 并覆盖:
API 24+:
WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request)
or
WebResourceResponse shouldInterceptRequest(WebView view, String url)
推荐阅读
- sql - 如何使用 URL slug 在 Postgres 中执行查询?
- google-sheets - 如何在 Google 表格的 QUERY 中使用 TEXT
- ssl - 无法将自签名证书与 tokio-rustls 一起使用
- android - 检测操作系统版本,然后建议用户安装应用程序
- javascript - 使用 javascript 为伪元素应用 css
- rust - 如何使用 release 编译一些依赖项
- ios - 当 UILabel 给出尾随时,自动布局被破坏
- python - How to reframe the dataset based on Id ignoring the null and empty lists
- snmp4j - SNMP4j - sned(pdu, target) 方法总是返回 null
- fpga - 带按钮的加/减计数器