移动到生产后获得访问令牌时,网页API请求无效 [英] web api Bad Request when getting access token after moving to production

查看:194
本文介绍了移动到生产后获得访问令牌时,网页API请求无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用一个访问令牌/承载认证工作在测试大的网络API。我验证和使用的HttpClient发出请求。很简单。

I have a web api that is working great in test using an access token / bearer authentication. I authenticate and make requests using HttpClient. Easy.

下面是基本的Web客户端安装。该基址是一个常数,我移动到生产的时候改变。

Here is the basic web client setup. The base address is a constant that I change when moving to production.

    public static HttpClient GetClient()
    {

        HttpClient Client = new HttpClient();

        Client.BaseAddress = new Uri(Ics2Constants.ICS2APIBaseAddress);
        Client.DefaultRequestHeaders.Accept.Clear();
        Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        return Client;
    }

我打造的令牌请求登录信息,像这样:

I build the token request login info like so:

       var values = new Dictionary<string, string>();
        values.Add("grant_type", "password");
        values.Add("username", "niceUser");
        values.Add("password", "NiCePaSsWord");
        var loginContent = new FormUrlEncodedContent(values);

然后我做了访问令牌请求:

And then I make the request for the access token:

        var loginResponse = await client.PostAsync("/Token", loginContent);

在测试模式,完善。我可以让我的访问令牌,它传回在后续请求。所有这些都是好的。

In test mode, perfect. I can get my access token, pass it back on subsequent requests. All is good.

当我移动到生产。我得到关于访问令牌请求错误请求400。我有基地址正确的,因为如果我脱下授权属性我找回数据。

When I move to production. I get a bad request 400 on the request for access token. I do have the base address right because if I take off the authorize attribute I can get data back.

东西大约是在生产访问令牌的要求不同,但我不知道该怎么改。

Something is different about the request for access token in production, but I have no clue what to change.

推荐答案

那么,答案结束了两部分:

Well, the answer ended up being two part:

1)问题与虚拟主机。他们对他们的最终腐败。

1) Issue with the web host. They had a corruption on their end.

2),他们的固定后的问题我还收到404(未找到)...所以我不得不采取了/在我PostAsync。因此,新行看起来像这样:

2) After they fixed their issue I still received a 404 (not found)... so I had to take out the "/" in my PostAsync. So the new line looks like so:

var loginResponse = await client.PostAsync("Token", loginContent);  

据曾在调试在本地端与/,但制作方却高兴不起来。

It worked in debug on the local side with the "/", but the production side was not happy.

我和现在的工作。 :)

I'm up and working now. :)

这篇关于移动到生产后获得访问令牌时,网页API请求无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆