title: Setting JSON request header in Angular2 HTTP POST
body: <p>I'm having a problem setting a content-type of application/json header on my post request.</p>
  
  <pre class="lang-js prettyprint-override"><code>    saveUpdates(alltabs: AllTabs): Observable&lt;Response&gt; {
              let api = this.host + this.routes.save;
              let headers = new Headers();
              headers.append('Content-Type', 'application/json');
  
              return this._http.post(api, JSON.stringify(alltabs), { headers: headers })
              .map((response: Response) =&gt; &lt;Response&gt;response.json())
              .do(data =&gt; console.log("saveUpdates(): " + data))
              .catch(this.handleError);
      }
  </code></pre>
  
  <p>Request Headers:</p>
  
  <pre><code>OPTIONS /api/productsave HTTP/1.1
  Host: wbtest:92
  Connection: keep-alive
  Pragma: no-cache
  Cache-Control: no-cache
  Access-Control-Request-Method: POST
  Origin: http://localhost:3000
  User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36
  Access-Control-Request-Headers: content-type
  Accept: */*
  Referer: http://localhost:3000/product/60000010080
  Accept-Encoding: gzip, deflate, sdch
  Accept-Language: en-US,en;q=0.8
  </code></pre>
  
  <p>Response Headers:</p>
  
  <pre><code>HTTP/1.1 405 Method Not Allowed
  Cache-Control: no-cache
  Pragma: no-cache
  Allow: POST
  Content-Type: application/json; charset=utf-8
  Expires: -1
  Server: Microsoft-IIS/7.5
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Access-Control-Allow-Origin: *
  Date: Tue, 14 Jun 2016 15:16:15 GMT
  Content-Length: 76
  </code></pre>
  
  <p>As you can see, my request has two unexpected headers added "Access-Control-Request-Headers" and "Access-Control-Request-Method". This seems to suggest an issue with CORS (Cross-Origin Resource Sharing). However, the web.conf file on the API server has been working and the response headers states "Access-Control-Allow-Origin: *".</p>
  
  <p>Any idea what could be wrong? </p>
  
  <p>UPDATE:</p>
  
  <p>The above code is correct - the problem is with the Sever code not being configured to handle preflight requests. In my case, the .NET Web API 2 application was not configured to allow CORS.</p>