2
我試圖驗證使用令牌QuickBlox的服務器時,有一個很大的問題。未經授權的訪問REST API
我使用的方法是:
public static async Task<LoginResponse> GetLoginResponseAsync(string email, string password)
{
LoginResponse result = null;
using (var client = new HttpClient())
{
string token = QbProvider.SessionResponse.Session.Token;
LoginRequest request = new LoginRequest()
{
Email = email,
Password = password
};
using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, LoginUrlRequest))
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("QB-Token", token);
using (var response = await client.SendAsync(requestMessage))
{
string json = response.Content.ReadAsStringAsync().Result;
result = JsonConvert.DeserializeObject<LoginResponse>(json);
}
}
}
return result;
}
服務器的響應是:
{ 「錯誤」:[ 「令牌需要」]}
和集管(調試)在客戶端對象是:
{
StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Date: Thu, 01 Jun 2017 12:05:29 GMT
QuickBlox-REST-API-Version: 0.1.1
Server: openresty/1.9.15.1
Status: 401 Unauthorized
Strict-Transport-Security: max-age=31536000
WWW-Authenticate: OAuth realm=users
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Request-Id: 584a0dca-fc44-4114-9626-327ac1729f67
X-Runtime: 0.003430
X-XSS-Protection: 1; mode=block
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Content-Length: 32
}
}
當我在Postman中使用令牌時,服務器的響應是succ essfull。
你知道我在做什麼錯?
非常感謝你提前! 此致敬禮。
你有沒有進行相互比較的要求 - 與你的代碼郵差。您可以使用[Fiddler](https://www.telerik.com/download/fiddler/fiddler2)等工具來比較請求。 – Gururaj
你可以確認,如果令牌取自會話變量 – Saravanan
根據文件,我認爲你必須使用用戶的會話令牌https://quickblox.com/developers/Authentication_and_Authorization#Requests_and_Responses – Saravanan