title: How to make POST request to external API using Angular2?
body: <p>I'm trying to leverage CORS to make a post request. I came across several articles/answers related to <strong>CORS</strong> but somehow just couldn't get it working. </p>
  
  <p>As I understand, the <code>access-control-allow-origin: *</code> is to be set on the server side to get this working but what I have here is a angular-cli project.</p>
  
  <p>My project is purely Angular 2.1 based and no backend server is involved. Any suggestions as to how to set it up properly will be highly appreciated.</p>
  
  <p>The exact error that I'm getting is this:</p>
  
  <pre><code>"NetworkError: 404 Not Found - https://flowxo.com/hooks/a/rbpja7r2/?usertype=User"
  </code></pre>
  
  <p>and this warning in console:</p>
  
  <pre><code>Cross-Origin Request Blocked: The Same Origin Policy disallows reading the
  remote resource at https://flowxo.com/hooks/a/rbpja7r2/?usertype=User.
  (Reason: CORS header 'Access-Control-Allow-Origin' missing).
  </code></pre>
  
  <p>Update:</p>
  
  <p>Here's how I'm trying to make a POST request:</p>
  
  <pre><code>let headers = new Headers();
  headers.append('Access-Control-Allow-Headers', 'Content-Type');
  headers.append('Content-Type', 'application/json');
  headers.append('Access-Control-Allow-Methods', 'POST, OPTIONS');
  headers.append('Access-Control-Allow-Origin', '*');
  return this.http.post(
      this.flowxoUrl,
      JSON.stringify(formData),
      {headers: headers}
    )
    .map((res:Response) =&gt; res.json())
    .catch((error:any) =&gt; Observable.throw(error.json().error || 'Server error')); //...errors if any
  </code></pre>