这是我的代码:
let authorizationData = 'Basic ' + btoa('username' + ':' + 'password');
const headerOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': authorizationData
})
};
return this.http.post(`URL`, {}, headerOptions);
我在控制台中得到以下信息: OPTIONS'URL'网络:: ERR_CERT_AUTHORITY_INVALID
请求标头如下所示:
Provisional headers are shown
Access-Control-Request-Headers: authorization
Access-Control-Request-Method: POST
Origin: http://localhost:4200
Referer: http://localhost:4200/register
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
当我在控制台中检查headerOptions时,对我来说有点奇怪:
headerOptions: Object
headers: HttpHeaders
lazyInit: ƒ ()
lazyUpdate: null
normalizedNames: Map(0)
size: (...)
看不到我正在创建的实际值。 请帮助我了解所有这些工作原理。
谢谢。