Text response is empty when using fetch

后端 未结 1 397
被撕碎了的回忆
被撕碎了的回忆 2021-01-19 10:21

The following code:

fetch(\'http://localhost:8080/root/1487171054127/k_query_bearer_token\', {
        mode: \'no-cors\', credentials: \'include\'
    })
            


        
相关标签:
1条回答
  • 2021-01-19 10:41

    Remove mode: 'no-cors'.

    When you use no-cors mode, you’re explicitly specifying that you want an “opaque response”.

    Your script can’t access any properties of an opaque response—instead essentially all you can do is cache it. no-cors mode is basically useful only when doing caching with Service Workers.

    If the reason you have your script using no-cors mode is because cross-origin requests to the server otherwise won’t work, the right solution is either to update the server-side code to send the Access-Control-Allow-Origin response header and other CORS headers—if you have access to the server do to that—or else, use a reverse proxy like https://cors-anywhere.herokuapp.com/.

    0 讨论(0)
提交回复
热议问题