admin管理员组文章数量:1310074
If I run the following:
fetch('http://localhost:8080/root/1487171054127/k_query_bearer_token',{mode: 'no-cors'}).
then(response=>response)
from within my webapp hosted via localhost:11111 I get a 401 error.
However if I open a tab in the same browser and enter http://localhost:8080/root/1487171054127/k_query_bearer_token then I get a 200 response.
What am I doing wrong?
UPDATE
This is working via curl:
curl 'http://localhost:8080/gui/root/1487171054127/k_query_bearer_token' -H 'Cookie: JSESSIONID=CviS9IK8pcsqADdP-m0MRXX_AvUqfzjJPwk1Yytf.ee16d0a01ad5'
So I need to provide a cookie
If I run the following:
fetch('http://localhost:8080/root/1487171054127/k_query_bearer_token',{mode: 'no-cors'}).
then(response=>response)
from within my webapp hosted via localhost:11111 I get a 401 error.
However if I open a tab in the same browser and enter http://localhost:8080/root/1487171054127/k_query_bearer_token then I get a 200 response.
What am I doing wrong?
UPDATE
This is working via curl:
curl 'http://localhost:8080/gui/root/1487171054127/k_query_bearer_token' -H 'Cookie: JSESSIONID=CviS9IK8pcsqADdP-m0MRXX_AvUqfzjJPwk1Yytf.ee16d0a01ad5'
So I need to provide a cookie
Share Improve this question edited Feb 15, 2017 at 15:46 Baz asked Feb 15, 2017 at 15:39 BazBaz 13.2k40 gold badges152 silver badges279 bronze badges 1-
So are you asking how to provide a cookie via
fetch
, or have you solved your issue now? – James Thorpe Commented Feb 15, 2017 at 15:49
1 Answer
Reset to default 11To automatically send cookies for the current domain, the credentials option must be provided:
fetch('/users', {
credentials: 'same-origin'
})
本文标签: javascriptCall to fetch returning 401Stack Overflow
版权声明:本文标题:javascript - Call to fetch returning 401 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741856177a2401355.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论