小编Luc*_*pel的帖子

如何从浏览器中的提取请求中获取标头位置值

从ReactJS-Redux前端应用程序,我尝试获取REST API响应的Location Header值。

当我卷曲时:

curl -i -X POST -H "Authorization: Bearer MYTOKEN" https://url.company.com/api/v1.0/tasks/
Run Code Online (Sandbox Code Playgroud)

我有这个答案:

HTTP/1.1 202 ACCEPTED
Server: nginx
Date: Fri, 12 Aug 2016 15:55:47 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: keep-alive
Location: https://url.company.com/api/v1.0/tasks/status/idstatus
Run Code Online (Sandbox Code Playgroud)

当我在ReactJS中进行抓取时

    var url = 'https://url.company.com/api/v1.0/tasks/'
    fetch(url, {
            method: 'post',
            credentials: 'omit',
                headers: {
                    'Authorization': `Bearer ${token}`
                }
            }
     )
Run Code Online (Sandbox Code Playgroud)

我在响应对象中没有任何标头Fetch请求中没有标头

我尝试了在https://developer.mozilla.org/zh-CN/docs/Web/API/Headers中找到的所有response.headers函数:

response.headers.get('Location');
Run Code Online (Sandbox Code Playgroud)

但是,由于标题为空,因此结果为空。

您知道为什么我无法获得包含标题值的正确Header对象吗?

http-headers fetch-api

4
推荐指数
1
解决办法
7150
查看次数

标签 统计

fetch-api ×1

http-headers ×1