WebException: Error: ConnectFailure (No route to host)

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://10.0.xx.xx/myService.aspx"));
request.ContentType = "application/json";
request.Method = "GET";
var response = request.GetResponse();

This code works fine from a visual studio console app but when running from xamarin studio and the android emulator it results in the exception:

Any help appreciated. Is this a licencing thing? Just running trial

more detail attached

Answers

  • MihaMarkicMihaMarkic SI ✭✭✭✭

    I'd say that your device lives on different IP address that your computer does and that IP is unreachable from it.
    Try accessing that IP from within a browser on the device and you'll see.

  • ANBINANILANBINANIL USMember ✭✭

    Hey, Guys, this error occurs due to lack of data connection.Please check data is ON

  • TBMSamTBMSam Member ✭✭
    edited December 2018

    okay @MihaMarkic but what to do? how to fix/change this so that they have the same ip or whatever?

  • knudmtknudmt Member ✭✭

    Android routes things a little differently. But you should take note of whether you are running IIS Express or not.
    The problem is that the Android emulator maps 10.0.2.2 to 127.0.0.1, not to localhost. So configure your web server to server on 127.0.0.1:portNumber and not localhost:portnumber. That should do it.

  • brikesh987brikesh987 Member

    For someone reading it now. The answers given above worked for me. Instead of accessing the web api from local machine, I pushed the service to cloud and then device had no issue in accessing it. Make sure wifi is enabled on the device.

Sign In or Register to comment.