I am trying to make a POST call using HttpClient
in an Angular 5 project, and I want to set the header:
import { HttpClient, HttpHeaders, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AuthData } from './models/auth-data';
@Injectable()
export class AuthService {
constructor(private http: HttpClient) { }
auth = (data: AuthData) => {
var url = "https://.../login";
var payload = data;
var headers = new HttpHeaders().set('Content-Type', 'application/json; charset=utf-8');
var options = {
headers: headers
};
this.http.post(url, payload, options).subscribe();
}
}
For some reason, the Content-Type
header does not seem to be in the request I am making.
Why is this?
This worked for me. Instead of append.
let headers = new HttpHeaders({ 'Content-Type': 'application/json' });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With