Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

"System.Net.WebException: 'Failed to connect to localhost/127.0.0.1:44391'" I got those error,

sjinsjin Member ✭✭

Hi
I am new for Xamarin. form,

I try to use Asp.net Api, and integrate with my Xamarin form app, but cannot connect to my Xamarin App with Api.

but using Postman, directly input data to my Asp.net Api working perfectly.

I got this message from Xamarin form.
"System.Net.WebException: 'Failed to connect to localhost/127.0.0.1:44391'"

My code below:

public class ApiServices
{
    public async Task<bool> RegisterAsync(string phone, string password, string confirmPassword)
    {
        var client = new HttpClient();

        var model = new RegisterBindingModel
        {
            phone = phone,
            password = password,
            passwordconfirm = confirmPassword
        };
        var json = JsonConvert.SerializeObject(model);

        HttpContent content = new StringContent(json);

        content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); 

        var response = await client.PostAsync("http://localhost:44391/api/login/", content);

        return response.IsSuccessStatusCode;
    }
}

That is my code for connecting Api.

I don't know why i got 127.0.0.1 coming from.

Thank you. guys.

Best Answer

Answers

Sign In or Register to comment.