Having trouble making a POST request in Angular 5 that accepts text/plain
as a response. The method being called in Angular expects a JSON
response, causing an error when trying to parse the response.
Attempted to call the method with parameter {responseType: 'text'}
, but encountering errors in VS code and the console during compilation of the application.
Here is the Angular 5 code for a POST request expecting a response as text/plain
.
this.http
.post<string>(this.loginUrl, this.user, {responseType: 'text'}) // error in this line
.subscribe(
(data) => this.success(data),
(error) => this.failure(error)
);
Upon compilation, the following error appears in the console:
ERROR in src/app/login/login.component.ts(47,47): error TS2345: Argument of type '{ responseType: "text"; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
Types of property 'responseType' are incompatible.
Type '"text"' is not assignable to type '"json"'.