动态图像无法加载,显示为 text/html MIME 类型,修复了 webview 问题?

Dynamic images won't load, shows up as text/html MIME type, fix for webview?

例如,其中一张图片的 link 转到 url https://storage.notmywebsite.com/some/path/on/website/image:Static,Small/ImageFileName?params=123456

当通过 chrome://inspect 调试 webview 时,出现的错误类型是...

跨源读取阻止 (CORB) 阻止了 MIME 类型 text/html 的跨源响应 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。有关详细信息,请参阅 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);