【发布时间】:2016-12-20 00:30:16
【问题描述】:
从 ReactJS - Redux 前端应用程序,我尝试获取 REST API 响应的 Location Header 值。
当我卷曲这个时:
curl -i -X POST -H "Authorization: Bearer MYTOKEN" https://url.company.com/api/v1.0/tasks/
我有这个答案:
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
当我在 ReactJS 中进行 Fetch 时
var url = 'https://url.company.com/api/v1.0/tasks/'
fetch(url, {
method: 'post',
credentials: 'omit',
headers: {
'Authorization': `Bearer ${token}`
}
}
)
我在响应对象中没有任何标题: No header in Fetch request
我尝试了我在https://developer.mozilla.org/en-US/docs/Web/API/Headers 中找到的所有 response.headers 函数:
response.headers.get('Location');
但是,由于标题为空,我的结果为空。
你知道为什么我不能得到一个正确的 Header 对象来填充标题值吗?
【问题讨论】:
-
fetch api 可能只公开某些标头。 stackoverflow.com/a/5837798/1515758
-
谢谢@John,它帮了我很多。