【发布时间】:2021-08-25 13:59:51
【问题描述】:
我正在尝试使用 Angular httpClient 将 ndjson 块发送到 API。我要联系的端点不接受对象数组,并且每个 JSON 对象都必须用换行符来描述。因此,我不能只使用典型的 JSON 对象,而是使用一串 JSON 对象,每个对象后面都有一个换行符。然后我尝试将 Content-Type 标头设置为 applicaiton/json,因为 API 仍然需要它,但是当请求发出时,httpClient 会覆盖我的标头并将其设置回 text/plain。
如何防止这种覆盖发生?
代码:
bulkImport(importData: string, indexName: string){
const headers = new HttpHeaders();
headers.set('Content-Type', 'application/json; charset=utf-8');
return this.http.put<any>(this._baseUrl + indexName + "/_bulk", importData, {headers: headers});
}
【问题讨论】:
-
试试:
const headers = { 'Content-Type': 'application/json'}; -
谢谢!那行得通
标签: angular angular-httpclient