我正在使用库isomorphic-unfetch (https://www.npmjs.com/package/isomorphic-unfetch)从Rest API获取JSON数据。下面是我提出请求的方式:
const res = await fetch(
`url`
);要访问正文,我只需执行以下操作
const response = await res.json()但是我如何访问响应头呢?如果我将响应记录到我的服务器控制台,这是我看到的:
Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: {
// stuff
},
[Symbol(Response internals)]: {
url: 'request url',
status: 200,
statusText: 'OK',
headers: Headers { [Symbol(map)]: [Object: null prototype] },
counter: 0
}
}什么是Symbol(Response internals)?那么如何访问它的headers属性呢?
发布于 2020-03-03 09:35:11
要访问其headers,请使用以下方法之一:
const res = await fetch(url);
console.log(res.headers.get('content-type');
// or
res.headers.forEach(header => console.log(header));https://stackoverflow.com/questions/60393861
复制相似问题