首页 > 解决方案 > 动态图像无法加载,显示为 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 网络浏览器中加载相同的网站时,这些图像会显示出来......所以出了什么问题?有没有什么办法解决这一问题?

标签: android-webviewandroid-developer-apiandroid-websettingscross-origin-read-blockingandroid-chrome

解决方案


我终于弄清楚出了什么问题。

对于 webview,它需要再打开一项设置,以便使用网站的 cookie 来访问受凭据保护的图像。

因此,如果您想为您的应用程序修复它,只需使用以下代码。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
else
    CookieManager.getInstance().setAcceptCookie(true);

推荐阅读