admin管理员组

文章数量:1394520

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

本文标签: