Android Webview:禁用 CORS [英] Android Webview: disable CORS

查看:71
本文介绍了Android Webview:禁用 CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 是否允许原生应用为 http://(非本地/文件)请求禁用 CORS 安全策略?

Does Android allow native apps to disable CORS security policies for http:// (not local/file) requests?

在我的本机应用程序中,webview 通过 http://显示远程 html,而不是在本地/文件系统上.这似乎与在网络浏览器中一样受到 CORS 限制.

In my native app, a webview shows a remote html via http://, not on the local/file system. This seems to be CORS-restricted in the same way as within webbrowsers.

Worakround:用于跨域的 ajax 请求的原生 js 桥,没有 Access-Control-Allow-Origin: * 是我的快速解决方案.(jsonp 或服务器端代理不是一个选项,因为客户端的 cookie+ip 是由 web 服务检查的.)

Worakround: A native-js bridge for ajax requests to cross-domains which do not have Access-Control-Allow-Origin: * is my quick'n'dirt solution. (jsonp or server-side proxy is not an option because cookie+ip of client are checked by the webservice.)

可以为应用内网页视图禁用此政策吗?

Can this policy be disabled for inapp webviews?

请让我知道,如果有一个简单的标志允许 js 绕过这个限制原生"应用程序的 web 视图的限制.

Please let me know, if there is a simple flag for allowing js to bypass this restriction which limits the "native" app's webview.

推荐答案

AFAIK 这是不可能的,相信我,我已经尝试了很多方法.

AFAIK this is not possible, and believe me, I've tried many ways.

您能做的最好的事情就是覆盖资源加载.请参阅拦截和覆盖来自 WebView 的 HTTP 请求

The best you can do is override resource loading. See Intercept and override HTTP-requests from WebView

这篇关于Android Webview:禁用 CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆