I keep getting errors NameResolutionFailurewhen creating web requests (GET) in MVVM Cross app for Android.
I have tried most of the recommendations provided on the forums in this question, as it is common, but I cannot fix it.
My current attempt is using the NuGet package ModernHttpClientto execute web requests. The same error occurred - it was not possible to resolve the domain for the IP address, however, the error message is slightly different from what happened when using HttpWebRequest, so I assume that this is a slight improvement?
java.net.UnknownHostException: cannot resolve host "jsonplaceholder.typicode.com": no address associated with host name
Can you give some advice on why this always fails? Maybe his is my method that uses it incorrectly ModernHttpClient?
The following code is part of my class IRestServicelocated in CorePCL, not in an Android project.
public async Task MakeRequest(WebHeaderCollection headers = null)
{
var handler = new NativeMessageHandler();
string requestUrl = "http://jsonplaceholder.typicode.com/posts/1";
try
{
using (var client = new HttpClient(handler))
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.GetAsync(requestUrl);
if (response.IsSuccessStatusCode)
{
var stream = await response.Content.ReadAsStreamAsync();
var reader = new StreamReader(stream);
Mvx.Trace("Stream: {0}", reader.ReadToEnd());
}
}
}
catch (WebException ex)
{
Mvx.Trace("MakeRequest Error: '{0}'", ex.Message);
}
return;
}
PS: I also tried using the Cheesebarons ModernHttpClient MVVM Cross plugin, but it causes compilation errors in release mode and there is no documentation about which methods and classes it has - maybe it is no longer supported?
PPS: And yes, my manifest has permission to access the Internet (I check the parameters and the actual manifest file for confirmation)
source
share