php – Could someone help me with this error?(Xamarin.Forms) "System.Net.Http.HttpRequestException: 'Network subsystem is down'"-ThrowExceptions

Exception or error:

So I’m making an Android and IOS application with Xamarin and i try to fix my problem but I strugle with it. I made a register page were a new user can registrate himself but when they click on SignUp the app switches in break mode and the error occures. So as you can see in the code i’ve also a php script that adds a new user to mysql database using a query when clicking on signup button.

This is the error that I have:

” System.Net.Http.HttpRequestException: ‘Network subsystem is down’ ” (–> breakmode)

The code behind looks like this:

 public async void SUButton_Clicked(object sender, EventArgs e)
    {


        if (string.IsNullOrWhiteSpace(UsernameEntry.Text) || string.IsNullOrWhiteSpace(AgeEntry.Text) || string.IsNullOrWhiteSpace(EmailEntry.Text) || string.IsNullOrWhiteSpace(PasswordEntry.Text) || string.IsNullOrWhiteSpace(RepeatPasswordEntry.Text))
        {
            await DisplayAlert("Enter all information", "", "Close");
        }
        else
        {
            if (PasswordEntry.Text == RepeatPasswordEntry.Text)
            {

                user u = new user();

                var _content = new FormUrlEncodedContent(new[]
                {
                   new KeyValuePair<string, string>("Id", u.Id),
                   new KeyValuePair<string, string>("Username", u.Username),
                   new KeyValuePair<string, string>("Email", u.Email),
                   new KeyValuePair<string, string>("Passwd", u.Passwd),
                   new KeyValuePair<string, string>("Age", u.Age)
                });


                var _result = await _client.PostAsync("http://localhost/DATA/USER/CreateUser.php", _content).ConfigureAwait(false);

                var _tokenJson = await _result.Content.ReadAsStringAsync();

                var _post = JsonConvert.DeserializeObject<RestApiReturn>(_tokenJson);

                var result = await DisplayAlert("Succesfull sign up", null, null, "Close");
                if (result == false)
                {
                    new MainPage();
                }
            }
            else
            {
                await DisplayAlert("The entered passwords aren't the same", "", "Close");
            }
        }
        UsernameEntry.Text = AgeEntry.Text = EmailEntry.Text = PasswordEntry.Text = RepeatPasswordEntry.Text = string.Empty;



    }

I’ve also made two appart classes for ‘user’ and ‘RestApiReturn’:

Could someone help me with my problem! Thank you all!

How to solve:

This line tells your program to contact a php web app’s POST endpoint.

var _result = await _client.PostAsync("http://localhost/DATA/USER/CreateUser.php", _content).ConfigureAwait(false);

http://localhost/ tells your program to contact a php web app running on your android device.. It seems unlikely that your web app is actually on your device; it’s probably on a server. So you need to use http://server.example.com/ instead, substituting your server’s hostname for the example hostname.

localhost is a hostname for the IP address 127.0.0.1, which always means “this machine”. It’s called the loopback address.

Your error message says that the device’s network subsystem is down. That could be for any number of reasons.

  • Typically when debugging programs running on devices, the devices should be connected by
    WiFi to the same LAN that runs your servers. Check that connection.
  • Your device may, for some reason, give this message when you try to connect to a server on the loopback address that is not present.
  • The network could actually be down on your device. Is it in airplane mode? Is it disconnected from WiFi and also without a data plan from a wireless carrier? (My development devices don’t have wireless plans; I’m too thrifty to pay for them.)

Networking issues can be a pain in the neck to troubleshoot. Good luck.

Leave a Reply

Your email address will not be published. Required fields are marked *