我正在尝试从Anroid仿真器发送请求。但是应用程序没有给出正确的输出并中断了client.sendasync

时间:2018-07-25 13:31:00

标签: xamarin.forms.listview

{ 
   var keyValues = new List<KeyValuePair<string, string>>
   {
        new KeyValuePair<string, string>("username",username),
        new KeyValuePair<string, string>("password",password),
        new KeyValuePair<string, string>("grant_type","password")
   };

   var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost(delibirately written)/Token");
   request.Content = new FormUrlEncodedContent(keyValues);

   var client = new HttpClient();
   var response = await client.SendAsync(request);
   var jwt = await response.Content.ReadAsStringAsync();
   JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);

   var accessToken = jwtDynamic.Value<string>("access_token");
   var accessExpires = jwtDynamic.Value<DateTime>(".expires");
   Settings.AccessTokenExpiration = accessExpires;

   Debug.WriteLine(jwt);

   return accessToken;
}

我首先遇到异常,然后使用try catch,然后发现应用程序在client.async处中断。

0 个答案:

没有答案