我创建了一个 api 来获取数据,但它显示超时错误。我正在调用运行应用程序时调用的 Xamarin 主函数内部的函数。
public MainPage()
{
InitializeComponent();
//this.BindingContext = new PatientViewModel();
Task<PatientModel> abc = GetPatientData();
}
我的 api GetAsync 调用函数:
public async Task<PatientModel> GetPatientData()
{
PatientModel patient = null;
try
{
Uri weburl = new Uri("myuri");
HttpClient client = new HttpClient();
Console.WriteLine("a");
HttpResponseMessage response = await client.GetAsync(weburl);
Console.WriteLine("b");
if (response.IsSuccessStatusCode)
{
Console.WriteLine("in");
patient = await response.Content.ReadAsAsync<PatientModel>();
Console.WriteLine("in funciton");
return patient;
}
return patient;
}catch(Exception ex)
{
Console.WriteLine(ex);
return patient;
}
}
}
代码没有显示任何错误。当执行到 GetAsync 语句时,它会等待一段时间并发生异常。
System.Net.WebException: The request timed out. ---> Foundation.NSErrorException: Exception of type 'Foundation.NSErrorException' was thrown.
慕码人2483693
POPMUISE
相关分类