我尝试验证用户登录成功以便传递到我的应用的第一页,因此我尝试在令牌SendAsync方法上获得200代码验证(如果成功与否)
以下是我的登录服务代码:
using Icquire.Models;
using Icquire.LoginPassword_RestClient;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.Diagnostics;
using Icquire.Views;
using Xamarin.Forms;
using System.Net;
namespace Icquire.Services
{
public class LoginPasswordServices
{
public async Task GetLoginPasswordAsync(string userEmail, string userPassword, string message)
{
var keyValues = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("email", userEmail),
new KeyValuePair<string, string>("password", userPassword),
new KeyValuePair<string, string>("grant_type","password")
};
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:64661/Token");
request.Content = new FormUrlEncodedContent(keyValues);
var client = new HttpClient();
var response = await client.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();
Debug.WriteLine(content);
if (response.IsSuccessStatusCode)
message = "Sucesso";
else
message = "Usuário ou Senha não identificado";
}
};
}
问题是消息返回始终为false,尽管代码验证成功了200个代码。
有人能给我一个亮点吗?
先谢谢。 丹尼尔。