简体   繁体   English

请求 OAuth 令牌不能使用代码,但可以使用 Postman

[英]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.

相关问题 为什么获取我的访问令牌在 Postman 中有效,但在我的代码中无效? - Why does getting my access token work in Postman but not in my code? 对 https://oauth2.googleapis.com/token 的发布请求在代码中一直失败,适用于 Postman - Post Request to https://oauth2.googleapis.com/token keeps failing in Code, Works on Postman oAuth2 令牌请求使用 C# HttpClient 失败但在 Postman 中工作 - oAuth2 token request failing using C# HttpClient but working in Postman 它在postman web中工作,但在代码中不起作用 - it's working in postman web and it does not work in the code 在 C# 中使用 OAuth 授权代码流请求 access_token 时收到 400 错误请求? - Receiving 400 Bad Request when requesting an access_token with OAuth Authorization Code Flow in C#? HTTP POST请求在Postman中有效,但在代码中无效 - HTTP POST request works in Postman but doesn't work in code HTTP请求在邮递员中有效,但在代码中不起作用 - HTTP Request works in postman but doesn't work in code WatiN不适用于LinkedIn OAuth令牌访问表 - WatiN does not works with LinkedIn OAuth token Access Form 为什么使用 DataDirectory 不起作用但使用完整路径有效? - Why does using DataDirectory not work but using a full path works? 请求RSS feed在浏览器中有效,但不能使用XmlDocument.Load() - Requesting RSS feed works in browser but not using XmlDocument.Load()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM