title: Angular 2: how to deal with Response for preflight has invalid HTTP status code 400. Bad request
body: <p>Im Trying to get HTTP GET request using Rest api of my magento.</p>
  
  <p>Below is the angular2 code to achieve the same!.</p>
  
  <pre><code> public ngOnInit() {
      let headers = new Headers({ 'Accept': 'application/json' });
      headers.append('Authorization', 'Bearer x9a278mu7xoh4k0jkj08doc5j4b3ac22');
      headers.append('Access-Control-Allow-Headers', 'Content-Type');
      headers.append('Access-Control-Allow-Methods', 'GET');
      headers.append('Access-Control-Allow-Origin', '*');
  
      let options = new RequestOptions({ headers: headers });
      return this.http.get('http://10.2.../Mage_ang2/index.php/rest/V1/customers/1',options)
          .map(response =&gt; console.log(response.json))
          .subscribe((items: Person[]) =&gt; {
              console.log('items: ' + items);
              this.people = items;
          }, error =&gt; console.log(error));
  
   }
  </code></pre>
  
  <p>I Get (which im assuming) a CORS issue.</p>
  
  <blockquote>
    <p>OPTIONS <a href="http://10.2.../Mage_ang2/index.php/rest/V1/customers/1" rel="nofollow noreferrer">http://10.2.../Mage_ang2/index.php/rest/V1/customers/1</a> </p>
    
    <p>XMLHttpRequest cannot load <a href="http://10.2.../Mage_ang2/index.php/rest/V1/customers/1" rel="nofollow noreferrer">http://10.2.../Mage_ang2/index.php/rest/V1/customers/1</a>. Response for preflight has invalid HTTP status code 500</p>
  </blockquote>
  
  <p>I have tried the below steps after workaround in google to fix the same, but unsuccessful.</p>
  
  <p>1) In magento .htaccess file, added </p>
  
  <p><strong>Header set Access-Control-Allow-Origin "*"</strong></p>
  
  <p>2) In the above angular 2 code added,</p>
  
  <p><strong>headers.append('Access-Control-Allow-Headers', 'Content-Type');</strong>
  ...</p>
  
  <p>...</p>
  
  <p>3) Tried changing content-type from application/json in </p>
  
  <p><strong>let headers = new Headers({ 'Accept': 'application/json' });</strong></p>
  
  <p>What am i missing.</p>
  
  <p>Need the proper solution to fix the CORS (from magento2 to angular2) issue.</p>
  
  <p>Suggestions welcome!</p>