不透明响应被定义为Fetch API的一部分,并表示在未启用CORS时对远程源发出的请求的结果.
关于如何使用不透明的响应(包括JavaScript和页面上的资源)存在哪些实际限制和"陷阱"?
我正在使用reactjs构建仅前端的基本Weather App。对于API请求,我正在使用Fetch API。在我的应用程序中,我从找到的简单API获取当前位置,并且该位置将其作为JSON对象给出。但是,当我通过Fetch API请求它时,出现此错误。
Failed to load http://ip-api.com/json: Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.
Run Code Online (Sandbox Code Playgroud)
因此,我进行了搜索,找到了解决此问题的多种解决方案。
那么,如何才能永久解决该问题?我可以用来解决Fetch API中HTTP请求的CORS问题的最佳解决方案是什么?
我们使用puppeteer,有时还使用playwright来运行一些集成测试。我们模拟了一些目标页面的脚本依赖项,这会导致子资源完整性哈希不匹配。
无法使用计算的 SHA 在资源“http://localhost:3000/static/third-party/adobe-target/at-js/2.4.0-cname/at.js”的“integrity”属性中找到有效摘要-256 完整性'47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='。资源已被封锁。”
有没有办法通过标志或配置属性禁用完整性哈希检查?
google-chrome chromium subresource-integrity puppeteer playwright
如下代码:
fetch('http://localhost:8080/root/1487171054127/k_query_bearer_token', {
mode: 'no-cors', credentials: 'include'
})
.then(function (response) {
return response.text();
})
.then(function (text) {
console.log('Request successful', text.length);
})
.catch(function (error) {
log('Request failed', error)
});
Run Code Online (Sandbox Code Playgroud)
输出:
Request successful 0
Run Code Online (Sandbox Code Playgroud)
如果我使用curl:
curl 'http://localhost:8080/root/1487171054127/k_query_bearer_token' \
-H 'Cookie: JSESSIONID=CviS9IK8pcsqADdP-m0MRXX_AvUqfzjJPwk1Yytf.ee16d0a01ad5'
Run Code Online (Sandbox Code Playgroud)
我得到一个文本形式的令牌(长度!= 0)。
如果我通过以下方式输出响应标头:
curl 'http://localhost:8080/root/1487171054127/k_query_bearer_token'
-H 'Cookie: JSESSIONID=CviS9IK8pcsqADdP-m0MRXX_AvUqfzjJPwk1Yytf.ee16d0a01ad5'
--head
Run Code Online (Sandbox Code Playgroud)
我得到:
HTTP/1.1 200 OK
Connection: keep-alive
X-Powered-By: Undertow/1
Server: JBoss-EAP/7
Content-Type: text/plain
Content-Length: 1730
Date: Wed, 15 Feb 2017 16:17:00 GMT
Run Code Online (Sandbox Code Playgroud)
为什么我无法通过提取获取任何文本?