title: Cannot post JSON to ASPNET Core via CORS (415 - Unsupported media type)
body: <p>I am having problems getting ASPNET CORE to receive json requests posted cross-domain from an AngularX client. I've looked around quite extensively but I am unable to find a question/solution to this specific variation of problem.</p>
  
  <p>I set up CORS on the server and the requests are coming through to the server side, but the controller action's parameter consists only of null values. I read somewhere that I have to decorate the parameter with <code>[FromBody]</code>, but when I do that the server returns a 415 Unsupported Media error to my AngularX client - but not to my Chrome PostMan plugin and not to </p>
  
  <p>Here is how I enable CORS on my server side</p>
  
  <pre><code>    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
      {
          app.UseMvc();
          app.UseCors("SiteCorsPolicy");
      }
  
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddMvc();
          var corsBuilder = new CorsPolicyBuilder();
          corsBuilder.AllowAnyHeader();
          corsBuilder.AllowCredentials();
          corsBuilder.AllowAnyMethod();
          corsBuilder.AllowAnyOrigin(); 
          CorsPolicy corsPolicy = corsBuilder.Build();
  
          services.AddCors(x =&gt; x.AddPolicy("SiteCorsPolicy", corsPolicy));
      }
  </code></pre>
  
  <p>My controller code looks like this</p>
  
  <pre><code>public class ValuesController : Controller
  {
      [HttpPost, Route("api/values/petes-test/")]
      public async Task&lt;PetesTestResponse&gt; List([FromBody]PetesTestQuery query)
      {
          var result = await ............;
          return result;
      }
  }
  </code></pre>
  
  <p>And my client-side code looks like this</p>
  
  <pre><code>const headers = new Headers({
    'Content-Type': 'application/json; charset=utf-8',
    'Accept': 'application/json'
  });
  
  return this.http.post(url, JSON.stringify(request), { headers: headers })
    .map((res: Response) =&gt; &lt;TResponse&gt;res.json());
  </code></pre>
  
  <p>}</p>
  
  <p>The headers from the client to the server are as follows</p>
  
  <pre><code>Request URL:http://localhost:4201/api/values/petes-test/
  Request Method:OPTIONS
  Status Code:415 Unsupported Media Type
  Remote Address:[::1]:4201
  Referrer Policy:no-referrer-when-downgrade
  Accept:*/*
  Accept-Encoding:gzip, deflate, sdch, br
  Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
  Access-Control-Request-Headers:content-type
  Access-Control-Request-Method:POST
  Connection:keep-alive
  Host:localhost:4201
  Origin:http://localhost:4200
  Referer:http://localhost:4200/
  User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
  </code></pre>