gpt4 book ai didi

angularjs - 系统异常 : Call to Node module failed with error: Error: URLs requested via Http on the server must be absolute

转载 作者:搜寻专家 更新时间:2023-10-31 23:45:55 24 4
gpt4 key购买 nike

System.Exception: Call to Node module failed with error: Error: URLs requested via Http on the server must be absolute. URL: /Account/GetUser/

从 Angular Universal 调用 http 时会发生此错误。从服务器上,我无权访问“位置”对象。

为什么 Angular 中有一个限制,阻止从相对 url 调用网络服务?

如何在不使用“位置”的情况下检索主机名?

最佳答案

我通过导入以下组件修复了这个问题...

从 '@angular/core' 导入 { Component, Inject };

然后我构造我的组件,例如

构造函数(http: Http, @Inject('ORIGIN_URL')originUrl: string){...

然后,当我想调用我的 API 时,我会这样做:

http.get(originUrl + 'YOUR API URI HERE').subscribe(result => {...});

关于angularjs - 系统异常 : Call to Node module failed with error: Error: URLs requested via Http on the server must be absolute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43300257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com