2017-08-28 5 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); 
    } 

に追加するか、やって行くの要求が

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

これはどのようなタイプですか? 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(); 
関連する問題