title: Web API request error in xamarin forms
body: <p>I am trying to develop an mobile application using asp.net web api and xamarin forms. Getting errors like this </p>
  
  <blockquote>
    <p>System.Net.Http.HttpRequestException: An error occurred while sending
    the request</p>
  </blockquote>
  
  <p>I developed all the application Mobile, Web in a same solution. Then Created web api with individual login using visual studio 2017.
  This is my source code for RegisterBinding model</p>
  
  <p><strong>RegisterBinding.cs</strong> </p>
  
  <pre><code>public class RegisterBindingModel
  {
      public string Email { get; set; }
  
      public string Password { get; set; }
  
      public string ConfirmPassword { get; set; }
  }
  </code></pre>
  
  <p>Then i created viewmodel for xamarin binding
  <strong>RegisterViewModel.cs</strong></p>
  
  <pre><code>    class RegisterViewModel
      {
      ApiServices _apiserv = new ApiServices(); 
      public string Email { get; set; }
      public string Password { get; set; }
      public string ConfirmPassword { get; set; }
      public string Message { get; set; }
  
      public ICommand RegisterCommand {
          get
          {
              return new Command(async() =&gt;
              {
                  var isSucess = await _apiserv.RegisterAsync(Email, Password, ConfirmPassword);
                  if (isSucess)
                  {
                      Message = "Sucessfully Registered!";
                  }
                  else
                  {
                      Message = "Try again";
                  }
              });
          }
      }
  }
  </code></pre>
  
  <p>Also i create apiservice to connect mobile app and web api service</p>
  
  <p><strong>ApiService.cs</strong></p>
  
  <pre><code>public async Task&lt;bool&gt; RegisterAsync(string email, string password, string confirmPassword)
          {
              try
              {
                  var client = new HttpClient();
  
                  var model = new RegisterBindingModel
                  {
                      Email = email,
                      Password = password,
                      ConfirmPassword = confirmPassword
                  };
  
                  var json = JsonConvert.SerializeObject(model);
  
                  HttpContent _content = new StringContent(json);
  
                  _content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
  
  
                  var response = await client.PostAsync("http://localhost:54996/api/Account/Register", _content);
                  return response.IsSuccessStatusCode;
  
              }
              catch (System.Exception)
              {
  
                  throw;
              }
  
  
          }
  </code></pre>
  
  <p>Finally my view for xamarin xaml is</p>
  
  <p>RegisterPage.cs</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
               xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
               x:Class="CIDSCONMOB.Views.RegisterPage"
              xmlns:vm="clr-namespace:CIDSCONMOB.ViewModels"&gt;
  
      &lt;ContentPage.BindingContext&gt;
          &lt;vm:RegisterViewModel/&gt;
      &lt;/ContentPage.BindingContext&gt;
  
      &lt;StackLayout Orientation="Vertical"&gt;
          &lt;Entry Text="{Binding Email}"
                 Placeholder="Email"/&gt;
          &lt;Entry Text="{Binding Password}"
                 Placeholder="Password"
                 IsPassword="True"/&gt;
          &lt;Entry Text="{Binding ConfirmPassword}"
                 Placeholder="Confirm Password"
                 IsPassword="True"/&gt;
          &lt;Button Command="{Binding RegisterCommand}"
                   Text="Sign Up"/&gt;
          &lt;Label Text="{Binding Message}"/&gt;
      &lt;/StackLayout&gt;
  
  &lt;/ContentPage&gt;  
  </code></pre>
  
  <p>This is the Error when i click the register button</p>
  
  <p><a href="https://i.stack.imgur.com/FdeeL.png" rel="nofollow noreferrer">HTTP Exception</a></p>
  
  <p>As i am very new to xamarin development please help me to find solution for this issue</p>