【发布时间】:2018-07-05 13:47:46
【问题描述】:
我在 ASP.NET 中创建了一个托管在 Web 服务器上的 Web API。此 Web API 访问 SQL Server 中的一个表,其中我有一个名为 Products 和 Id, ProductName, Description and Price 的表,我通过 Postman 进行了测试,它工作正常,但是当我尝试使用该方法通过 Xamarin 带来特定产品时应用程序,我在中断模式下收到以下错误消息:
System.Net.Http.HttpRequestException: 超时获取异常详细信息
public class DataService
{
public async Task<List<Product>> GetProductAsync(string ProductName)
{
using (var client = new HttpClient())
{
string url = "http://ProductsAPI.hostname.com/api";
try
{
var uri = url + "/" + ProductName.ToString();
HttpResponseMessage response = await client.GetAsync(uri);
var ProductJsonString = awaitresponse.Content.ReadAsStringAsync();
var Product = JsonConvert.DeserializeObject<List<Product>>(ProductJsonString);
return Product;
}
catch (Exception ex)
{
throw ex;
}
}
}
}
【问题讨论】:
-
请求的状态码是什么? stackoverflow.com/questions/22217619/…
-
超时不是真正的错误,它是 Visual Studio 生成的错误。请检查错误详情。
-
我收到此消息未处理异常:System.Net.Http.HttpRequestException:发送请求时出错
-
您是否有任何代理限制或防火墙端口阻止?
-
可能会尝试使用 Fiddler (telerik.com/fiddler) 查看实际发出的请求并返回结果。
标签: c# xamarin xamarin.forms xamarin.android