[英]Requesting OAuth token does not work using code but works using Postman
I have tried to make my web API to generate a OAuth web API token using this Article .It worked fine testing it on postman我尝试使用这篇文章使我的 Web API 生成 OAuth Web API 令牌。它在邮递员上进行了很好的测试
but when I try to execute using the code that postman provides for the request I get response.Content=""
and response.StatusCode=0
但是当我尝试使用邮递员为请求提供的代码执行时,我得到
response.Content=""
和response.StatusCode=0
var client = new RestClient("https://ip_address/token");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddParameter("grant_type", "password");
request.AddParameter("username", "Morad.A");
request.AddParameter("password", "123456");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
What I have tried is adding我尝试过的是添加
if (ServicePointManager.SecurityProtocol.HasFlag(SecurityProtocolType.Tls12) == false)
{
ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
}
to my Application_Start()
in my web API到我的 Web API 中的
Application_Start()
Any suggestions?有什么建议?
Check the authorization type usually, OAuth requires Authoriaztion so you have to add auth value to request header.通常检查授权类型,OAuth 需要 Authoriaztion 所以你必须在请求头中添加 auth 值。 ie if auth typs is Basic just add the following:
即如果 auth typs 是 Basic 只需添加以下内容:
Authorization: Base64(client:secret)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.