最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net core - Visual Studio .http file returns 401 even though Authorization header is set for the request - Stack Overflow

programmeradmin6浏览0评论

I trying to consume a .NET Core Minimal Api endpoint, which is secured with Bearer tokens, via the .http client in Visual Studio.

I'm setting a valid Authorization: Bearer <token> in the request given below in my .http file,

@HostAddress = http://localhost:5085
@BearerToken = <token>

GET {{HostAddress}}/api/v1/categories
Accept: application/json
Authorization: Bearer {{BearerToken}}

but the response is always 401 Unauthorized.

I trying to consume a .NET Core Minimal Api endpoint, which is secured with Bearer tokens, via the .http client in Visual Studio.

I'm setting a valid Authorization: Bearer <token> in the request given below in my .http file,

@HostAddress = http://localhost:5085
@BearerToken = <token>

GET {{HostAddress}}/api/v1/categories
Accept: application/json
Authorization: Bearer {{BearerToken}}

but the response is always 401 Unauthorized.

Share Improve this question asked Mar 27 at 10:55 Rizan ZakyRizan Zaky 4,6925 gold badges29 silver badges41 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Since the endpoint host, @HostAddress = http://localhost:5085 is http and not https, it is likely that in the Program.cs file, you have configured, app.UseHttpsRedirection() which expects an https endpoint.

So, instead of http://localhost:5085 you must use the equivalent https endpoint for @MyAuth.Auth_HostAddress

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论