0

How I can set the httpheaders, I add this code

  public post (servicio: string, item: any): Observable<any> 
  {
    const url = `${SERVER_URL}${servicio}`;   
    const headers = new HttpHeaders().set('Content-Type', 'application/json; charset=utf-8')
    return this.http.post(url, item, {headers: headers})
     .do(data => console.log('All: ' + JSON.stringify(data)))
     .catch(this.handleError);
  }

In the chrome or fiddler the request is

Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:es-ES,es;q=0.8,en;q=0.6
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:localhost:56962
Origin:http://evil.com/
Referer:http://localhost:4200/entidad
User-Agent:Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Mobile Safari/537.36

2 Answers2

0

Finally works isn't in the headers, in the asp.net core cors I add the following

  app.UseCors(builder =>
              builder.WithOrigins("http://localhost:4200")
                           .AllowAnyHeader()
                           .AllowAnyMethod());
            app.UseMvc();
-1

Have a go doing this:

var headers = new Headers();
headers.append('Content-Type', 'application/json; charset=utf-8'); 
Chris
  • 4,672
  • 13
  • 52
  • 93