正在尝试使用 "http://localhost:61961/Token" 登录 Web API。收到 400 Bad Request 错误

Trying to Login to the Web API using the "http://localhost:61961/Token". Receiving 400 Bad Request Error

我是 C# 的新手。

我正在尝试使用 URL - http://localhost:61961/Token 登录 Web API Rest 服务。我收到错误 grant-type=invalid。我读到 Microsoft 已经为登录功能启用了单独的 Web 服务。为了从我的应用程序调用此服务,我将内容类型指定为 application/x-www-form-urlencodedgrant_type=password&username=[my Username which is an email]&password=[my password].

我们可以给 grant_type 赋值吗?

自定义登录功能比使用 Microsoft 登录功能更好吗?

感谢您的帮助。

我认为您需要仔细检查您的令牌功能。比 post 具体问题。 此外,在 grant_type 中,您可以输入任何值。从代码方面,它通过内置方法生成令牌,但您可以为其创建自定义方法。您必须在 google 上进行一些搜索,才能找到令牌生成功能的确切工作原理。

当我使用正确的 URL- http://localhost:[port 数字]/令牌时,我能够访问令牌服务。
我还以正确的格式给出了参数 - grant_type=password&username=[username]&password=[password]