0

I have this fragment of code (simplified), I try to send a custom header "foo-custom" using http.post, but the request in the browser is sent as a 200 OPTIONS. What is it due?

Import

import { Http, Headers, Response, RequestOptions } from '@angular/http'; 

App

const myheaders = new Headers();
myheaders.append('Content-Type', 'application/json');
myheaders.append('foo-custom', 'var');

const options = new RequestOptions({headers: myheaders});

this.http.post(
  this._url+'search', {}, options
).subscribe(data => {
  console.log("CORRECT!");
  console.log(data);
}, error => {
  console.log("ERROR!");
  console.log(error);    
});

What is the correct way to do it?

Thanks

Pablo M.
  • 494
  • 7
  • 14
  • **[Solution]** When there are custom-headers custom headers, they must be enabled explicitly in the CROS configuration of the Spring-boot API As a guide in the Spring-boot configuration, something like: `corsConfig.addAllowedHeader("authorization"); corsConfig.addAllowedHeader("other"); ` – Pablo M. Mar 28 '18 at 16:16

1 Answers1

0

It looks like a preflighted request, can you check this comment

Possible duplicated thread?