Forum Xamarin Xamarin.Forms

How do l ressolve System.Net.WebException Error .The Internet connection appears to be offline

AustyAusty Member ✭✭✭

The project l am building has some images on a file storage site and its consuming api's and it connected to the internet via my phone.After a lot of research l found out it has a bit to do with my using cellular network. l tried following this guide https://docs.microsoft.com/en-us/xamarin/cross-platform/macios/http-stack but it did not resolve my issue. Kindly Assist

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    What's the version of Visual studio on your side ? If it is in preview , just try to select stable channel and downgrade to the last stable release , refer the workaround .

  • AustyAusty Member ✭✭✭

    @ColeX l am using visual studio 2019 ver 8.2.4.. how do l know which version is stable and how do l downgrade

  • ColeXColeX Member, Xamarin Team Xamurai

    Navigate to Visual Studio - Check for Updates , select Stable channel , update visual studio if has newer version !

    PS : the latest stable visual studio is 8.3.8.8.

  • AustyAusty Member ✭✭✭

    @ColeX l updated to a new version of visual studio(stable)..but when l run the ios simulator l get the following error
    system.net.webexception... could not connect to the server.

    when l try to test the api in android simulator l get the following error

    system.net.webexception... failed to connect to \127.0.0.1:5000

    Below is the code

     public async void Comic()
            {
                //var handler = new NSUrlSessionHander();
                using (var httpClient = new HttpClient()){
                   var response = await httpClient.GetStringAsync("http://localhost:5000/api/comic");
                  //var response = await httpClient.GetStringAsync("http://10.0.2.2:56745/api/comic");
                    var comic = JsonConvert.DeserializeObject<List<Comic>>(response);
                    comicList.ItemsSource = comic;
                }
            }
    

    l am using a mac. Kindly help

  • ColeXColeX Member, Xamarin Team Xamurai
    edited November 2019

    The problem occurs while you try to access the local host , refer this thread , it provide several solutions for solving this issue .

  • AustyAusty Member ✭✭✭

    @ColeX the link you provided can not be accessed.

  • ColeXColeX Member, Xamarin Team Xamurai

    @Austy said:
    @ColeX the link you provided can not be accessed.

    Try again.

  • AustyAusty Member ✭✭✭

    @Colex Solved the issue.. Found out l was creating my own problems. These are the changes l made to solve the issue

    1. Called the api using localhost for ios simulator and 10.0.2.2 for android simulator
    2. set the project to start multi - projects
  • ColeXColeX Member, Xamarin Team Xamurai

    @Austy said:
    @Colex Solved the issue.. Found out l was creating my own problems. These are the changes l made to solve the issue

    1. Called the api using localhost for ios simulator and 10.0.2.2 for android simulator
    2. set the project to start multi - projects

    Great ! Please mark this thread as answered .

Sign In or Register to comment.