Angular "strict-origin-when-cross-origin" 错误是什么意思?

What does the Angular "strict-origin-when-cross-origin" Error mean?

我想通过我的应用访问 api。卷曲请求是:

curl --request POST   https://...    --header 'Authorization: Token ...'   --header 'Accept: application/csv'   --header 'Content-type: application/vnd.flux'   --data '...'

有效,returns 来自 InfluxDB 实例的数据。问题是当我在 Angular 中尝试所有操作时:我设置了一个正确重定向请求的代理(我在终端中检查了这个)。但是在网络浏览器(Firefox Developer Edition)中我得到

POSThttp://localhost:4200/api/
[HTTP/1.1 401 Unauthorized 204ms].

Status 401
Unauthorized
Version HTTP/1.1
Übertragen 350 B (55 B Größe)
Referrer Policy strict-origin-when-cross-origin

api URL 是https地址,http也会出现同样的错误。生产应用程序中也会发生同样的情况。

proxy.conf

{
"/api/*": {
"target": "...",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}

终端确认:

[HPM] POST /api/ -> correct url

组件中的请求:

apiurl = '/api/';
data = JSON.stringify('request');
headers:HttpHeaders = new HttpHeaders();;

constructor(private route: ActivatedRoute,
private httpClient: HttpClient) {
this.headers.set('Authorization', 'Token token');
this.headers.set('Content-type', 'application/vnd.flux');
}

getConfig() {
return this.httpClient.request<any>('post',`${this.apiurl}`,
    {
      body: this.data,
      headers: this.headers
    }
 );
}


ngOnInit(): void {

this.getConfig()
.pipe(first())
.subscribe(
 data => {
   console.log(data);
 },
 error => {
   console.log(error);
 });
  }

非常感谢您的想法,谢谢!

更改您的代理配置。

来自:

{
"/api/*": {
"target": "...",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}

为此:

{
"/api/*": {
"target": "...",
"secure": false,
"logLevel": "debug",
"changeOrigin": true,
"pathRewrite": { "^/api": "" }
}
}