0

I am trying to send a block of ndjson to an API with the Angular httpClient. The endpoint I am reaching out to does not accept an array of objects and each JSON object must be newline delineated. Because of this, I cannot just use a typical JSON object but rather a string of JSON objects with a newline after each. Then I am trying to set the Content-Type header to applicaiton/json because the API still requires it but when the request goes out, httpClient is overriding my header and setting it back to text/plain.

How would I prevent this override from happening?

Code:

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

1 Answers1

0

Thanks for the comment Najam Us Saqib! This worked:

const headers = { 'Content-Type': 'application/json'};

  • Check the duplicate question and use the HttpHeaders the correct way, instead of this workaround ;) Also makes you understand why your first attempt didn't work :) – AT82 Jun 08 '21 at 17:06