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
Add a ment  | 

1 Answer 1

Reset to default 11

To automatically send cookies for the current domain, the credentials option must be provided:

fetch('/users', {
  credentials: 'same-origin'
})

本文标签: javascriptCall to fetch returning 401Stack Overflow