fetch cros模式下 response.headers取空

fetch("img.png",{
    mode:"cros"
}).then(response=>{
    console.log(response.headers);//打印为空!
});

chrome.f12 network能看到headers数据的。

阅读 14.6k
4 个回答

服务器端header里面添加Access-Control-Expose-Headers:Captcha,将Captcha暴露出来,就可以获取到Captcha的值了

图片描述

console.log(response.headers.get('Content-Type'));这个取得到,
console.log(response.headers.get('Captcha'));这个取不到。
@不爱吃西红柿的鱼

那是个Header对象啊

得这样

fetch("img.png",{
    mode:"cros"
}).then(response => {
    console.log(response.headers.get('Content-Type'));
});
新手上路,请多包涵

可能是因为跨域了,就获取不到,后台设置在header里面的东西

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题