android-webview - 动态图像无法加载,显示为 text/html MIME 类型,修复 webview?
问题描述
例如,其中一张图片的链接转到 url https://storage.notmywebsite.com/some/path/on/website/image:Static,Small/ImageFileName?params=123456
。
通过 chrome://inspect 调试 webview 时,出现的错误类型是......
跨域读取阻止 (CORB) 阻止https://login.notmywebsite.com/login.srf?moreparams=123456&wreply=https:%2F%2Fstorage.notmywebsite.com%2Fstorageservice%2Fpassport%2Fauth.aspx%3Fsru%3Dhttps:%252f%252fstorage.notmywebsite.com%252fsome%252fpath%252fon%252fwebsite%252fimage:Static%252cSmall%252fImageFileName&otherparams=123456
了 MIME 类型 text/html 的跨域响应。有关详细信息,请参阅https://www.chromestatus.com/feature/5629709824032768 。
但是,在 Chrome 网络浏览器中加载相同的网站时,这些图像会显示出来......所以出了什么问题?有没有什么办法解决这一问题?
解决方案
我终于弄清楚出了什么问题。
对于 webview,它需要再打开一项设置,以便使用网站的 cookie 来访问受凭据保护的图像。
因此,如果您想为您的应用程序修复它,只需使用以下代码。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
else
CookieManager.getInstance().setAcceptCookie(true);
推荐阅读
- php - 将简码函数插入 php 行
- javascript - How to pass the value of a PHP function to a Javascript variable?
- java - 如何在 Java 中抓取我想要的 HTML 数据?
- javascript - Why readonly can be used only on array and tuple types?
- javascript - validator.js and detecting line breaks
- java - Bean method 'elasticsearchTemplate' not able to find in configuration
- javascript - ETIMEDOUT when making large(10k) post requests using axios.all nodejs
- django - how to create correct search when i use slug django
- javascript - Using something like ngRepeat in Javascript
- python - Files uploaded to s3 are missing content