【发布时间】:2017-07-04 10:15:01
【问题描述】:
以下代码:
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)
});
正在输出:
Request successful 0
如果我使用 curl:
curl 'http://localhost:8080/root/1487171054127/k_query_bearer_token' \
-H 'Cookie: JSESSIONID=CviS9IK8pcsqADdP-m0MRXX_AvUqfzjJPwk1Yytf.ee16d0a01ad5'
我得到一个文本形式的令牌(长度!= 0)。
如果我通过以下方式输出响应头:
curl 'http://localhost:8080/root/1487171054127/k_query_bearer_token'
-H 'Cookie: JSESSIONID=CviS9IK8pcsqADdP-m0MRXX_AvUqfzjJPwk1Yytf.ee16d0a01ad5'
--head
我明白了:
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
为什么我通过 fetch 没有收到任何文本?
【问题讨论】:
-
您的预期反应是什么? response.text() 将返回一个包含 USVString 的承诺:developer.mozilla.org/en-US/docs/Web/API/Body/text
标签: javascript cors fetch-api