【问题标题】:Can't change Content-Type in http post request using angular无法使用角度更改 http post 请求中的 Content-Type
【发布时间】:2019-09-18 15:48:39
【问题描述】:

我无法在 post 请求的标头中将 Content-Type 更改为 application/json。我使用角度 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

【问题讨论】:

标签: angular httpclient options


【解决方案1】:

解决方案:我使用了替换请求标头的 HttpInterceptor

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    • 2012-07-07
    • 2013-05-03
    • 2023-04-05
    • 2018-09-05
    • 1970-01-01
    相关资源
    最近更新 更多