该错误通常是由于未受信任的证书或错误的证书链导致的。要解决此问题,请按照以下步骤操作:
在浏览器中打开开发者工具。可以通过按F12或右键单击页面并选择“检查元素”来打开它们。
转到“安全性”或“网络”选项卡,并找到证书部分。
点击证书,并在弹出窗口中检查证书。
如果证书是错误的或未受信任的,则可能需要联系网站管理员以获取更新的证书。
如果证书是正确的但未受信任,则可以手动将其添加到受信任的根证书颁发机构(CA)列表中。
例如,以下是在Angular的httpHeaders中添加信任证书的示例:
import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core';
@Injectable({ providedIn: 'root' }) export class DataService {
constructor(private http: HttpClient) { }
getData() { const headers = {'Authorization': 'Bearer token_here', 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json'};
this.http.get('https://example.com/api/data', {headers: headers, withCredentials: true}).subscribe(res => {
console.log(res);
});
} }