REST查询的请求标头中的凭据

时间:2016-02-22 12:54:23

标签: c# vb.net rest google-chrome-app

我尝试从数据提供者token获取rest api。我尝试了以下代码以及Chrome Rest Console并始终获取401用户名或密码不正确。我仔细检查了这个并从提供者那里得到了它,我的username:pass组合是正确的。

也许问题就在这里。 API描述说:/authenticate(POST) username and password need to be send in the request header在Chrome和.net我使用basic auth,问题可能存在吗?或者是否有人有想法,因为我的想法已经不多了。

    Sub Main()
    Dim client = New RestClient("https://test.com/web/api")
    client.Authenticator = New Authenticators.HttpBasicAuthenticator("user.name", "password")
    Dim request = New RestRequest("/authenticate", Method.POST)
    Dim response As IRestResponse = client.Execute(request)
    response = client.Execute(request)
    Dim authroizationHeaderFromResponse = response.Headers.FirstOrDefault(Function(h) h.Name = "Authorization")
    Console.WriteLine(authroizationHeaderFromResponse.ToString)
    If authroizationHeaderFromResponse IsNot Nothing Then
        Console.WriteLine(authroizationHeaderFromResponse.Value)
    End If
End Sub

0 个答案:

没有答案