JS提取,未在响应中获取标头 [英] JS fetch, not getting headers on response

查看:106
本文介绍了JS提取,未在响应中获取标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用fetch到wordpress api发出请求,但是我在响应中得到一个空的标头对象,有人知道为什么吗?

I'm making a request using fetch to wordpress api, but I get a empty headers object on the response, anyone knows why?

这是我的提取操作

export const getJobs = () => {
  return dispatch => {
    fetch(endpoints.jobs)
      .then(res => res.json())
      .then(data => dispatch(setJobs(data)))
  }
};

这是我在执行res.json之前获得的对象

and here's the object that I get before doing res.json

body: (...)
bodyUsed: false
headers: {}
ok: true
redirected: false
status: 200
statusText: "OK"
type: "cors"
url: "url"

关于如何从响应中获取所有标头的任何想法?

any ideas on how I can get all the headers from the response?

推荐答案

使用CORS时,访问响应标头受到限制.由于您的回复类型是可能是罪魁祸首的罪魁祸首.

There is a restriction on accessing response headers when using CORS. Since your response type is cors that might be the culprit.

请参见回答以获取详细信息.

See this answer for details.

这篇关于JS提取,未在响应中获取标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆