我试图从模拟器访问本地启动的Api。 我尝试使用 http://10.0.2.2:hostport ,并且还尝试将 http://192.168.56.1:hostport 用于Genymotion模拟器。 但是我在下面的方法上下载了无尽的东西:
private async Task<HttpResponseMessage> SendRequestAsync(HttpRequestMessage request)
{
try
{
using (var client = new HttpClient())
{
return await client.SendAsync(request);
}
}
catch (ArgumentNullException e)
{
Console.WriteLine(e.Message);
throw;
}
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
throw;
}
catch (HttpRequestException e)
{
Console.WriteLine(e.Message);
throw;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw;
}
}
但是通过Rest Api或控制台程序,一切都很好。也许Windows阻止了我的请求?