使用提取时未发送授权标头

编程入门 行业动态 更新时间:2024-10-05 21:23:55
本文介绍了使用提取时未发送授权标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我尝试将Authorzation标头设置为以下标头时,该标头不会发送到请求的服务器.用fetch设置Authorization标头的正确方法是什么?

When I try and set the Authorzation header as below the header doesn't get sent to the server for the request. What's the correct way to set the Authorization header with fetch?

let options = { method: 'GET', headers: new Headers({ Authorization: 'Bearer ...' }) }; fetch('/api/somedata', options).then(function(response) { console.log(response); };

修改

在网络标签上的chrome开发人员工具中,我收到此请求:

In chrome developer tools on the network tab I get this for the request:

GET /api/somedata HTTP/1.1 Host: someserver.azurewebsites Connection: keep-alive User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 Accept: */* Referer: localhost:3000/somedata Accept-Encoding: gzip, deflate, sdch Accept-Language: en-US,en;q=0.8

请注意,未设置任何授权标头.

Note there's no Authorization header being set.

服务器响应:

HTTP/1.1 401 Unauthorized Content-Length: 61 Content-Type: application/json; charset=utf-8 Server: Microsoft-IIS/8.0 WWW-Authenticate: Bearer X-Powered-By: ASP.NET Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE Date: Thu, 29 Sep 2016 03:16:15 GMT

推荐答案

我相信您的服务器需要包含以下响应标头:

I believe your server needs to include the following response header:

Access-Control-Allow-Headers: Authorization

更多推荐

使用提取时未发送授权标头

本文发布于:2023-11-03 04:46:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554272.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!