无法使用 angular 更改 http post 请求中的 Content-Type

Can't change Content-Type in http post request using angular

我无法在 post 请求的 headers 中将 Content-Type 更改为 application/json。我用 angular 6。 请求被错误拒绝(不支持的媒体类型) 使用来自“@angular/http”的旧 http 的相同请求。

我对 运行 应用程序使用 visual studio 调试。 Web api 是 .net 核心。

import { HttpClient, HttpRequest, HttpEventType, HttpResponse, HttpHeaders 
} from '@angular/common/http';

var body = JSON.stringify(model);
let headers = new HttpHeaders();
headers = headers.set('Content-Type', 'application/json');

let httpOptions = {headers: headers,};

this.http.post(this.Url, body, httpOptions).subscribe(x => { })

Request result

解决方案:我使用 HttpInterceptor 替换请求 headers