title: StatusCode 400 "Bad request" when Connecting a Xamarin.forms app on a physical Phone to an Asp.net REST API
body: <p>Thanks for your attention.
  I'm trying to make a <code>Xamarin.Forms</code> App that communicates with a <code>REST</code> API.
  The API is fully functional, I've tested it with Postman and another WPF project.
  Upon trying to call a simple <code>GET</code> method with my <code>HttpClient</code>, I get the following <code>HttpResponseMessage</code></p>
  
  <pre><code>{
      StatusCode: 400, 
      ReasonPhrase: 'Bad Request', 
      Version: 1.1, 
      Content: System.Net.Http.StreamContent, 
      Headers:
      {
          Server: Microsoft-HTTPAPI/2.0
          Date: Sun, 17 May 2020 12:20:37 GMT
          Connection: close
          Content-Type: text/html; charset=us-ascii
          Content-Length: 334
      }
  }
  </code></pre>
  
  <pre class="lang-cs prettyprint-override"><code>
  public async Task TurnLEDOn()
  {
      HttpClient Client = new HttpClient(new System.Net.Http.HttpClientHandler());
  
      Client.DefaultRequestHeaders.Accept.Clear();
      Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/Json"));
      Client.BaseAddress = new Uri("https://192.168.1.2:44341/");
      HttpResponseMessage response = await Client.GetAsync("api/ChipCore/TurnLEDOn");
      if (response.IsSuccessStatusCode)
      {
          string receivedPerson = await response.Content.ReadAsAsync&lt;string&gt;();
      }
  }
  </code></pre>
  
  <p>This same code is run by a WPF program and works flawlessly.</p>
  
  <p>Both my phone and Laptop are connected to the same Wi-Fi network.</p>
  
  <ul>
  <li>I've allowed port <code>44341</code> through Firewall, I've even tried running
  the whole thing with Firewall off. The browser on my phone can't
  access the API. (Bad Request)</li>
  <li>I have tried changing the server url from <code>https</code> to <code>http</code> but faced
  a <code>trust anchor for certification path not found</code>
  I have added these Permissions to <code>android.manifest</code>:</li>
  </ul>
  
  <pre><code>CHANGE_NETWORK_STATE
  CHANGE_WIFI_STATE
  ACCESS_NETWORK_STATE
  INTERNET
  </code></pre>
  
  <p>Method in API</p>
  
  <pre><code>[RoutePrefix("api/ChipCore")]
  public class ValuesController : ApiController
  {
      [HttpGet]
      [Route("TurnLEDOn")]
      public bool TurnLEDOn()
      {
          return Switch.TurnLEDOn();
      }
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <ul>
  <li><p>I have tried bypassing the Certificate by adding this line to <code>MainActivity.cs</code></p>
  
  <p><code>ServicePointManager.ServerCertificateValidationCallback += (o, cert, chain, 
  errors) =&gt; true;</code></p></li>
  <li><p>I have tired putting in the URL in my phones browser, I get <code>Error 400 - Bad Request</code> </p></li>
  </ul>