我正在尝试HttpClient
在 Angular 5 项目中使用 POST 调用,并且我想设置标题:
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();
}
}
出于某种原因,Content-Type
标头似乎不在我提出的请求中。
为什么是这样?