2017-08-28 59 views
0

我如何可以設置httpheaders,我添加以下代碼角4.3 HttpClient的不發送內容類型標題

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); 
    } 

在Chrome或提琴手的請求

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 
+0

這是什麼類型的this.http? HttpClient的? –

+1

[Angular \ [4.3 \] HttpClient不能發送頭文件的可能的副本](https://stackoverflow.com/questions/45286764/angular-4-3-httpclient-doesnt-send-header) –

回答

-1

有去做這樣的:

var headers = new Headers(); 
headers.append('Content-Type', 'application/json; charset=utf-8'); 
0

最後的作品是不是在頭,在asp.net核心CORS我添加以下

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