我有一个在 heroku 上运行的 Angular 应用程序,它需要访问只能通过 QuotaGuard 中配置的 IP 访问的外部 API。
constructor(private http: HttpClient){}
proxy = new URL("http://username:password@ip:port");
private proxySend(){
this.http.get("http://targetlocation/").subscribe((data:any) => {
console.log("target-proxy:", data);
});
}
我在这里看到:使用 Heroku(不是 Proximo)的静态 IP 地址,在 ruby 中设置代理只是 httpClient 的配置,它在 Angular 中如何工作?我想在我的请求中使用代理,因为我的 heroku 应用程序有一个动态 IP,而使用静态的唯一方法是 QuotaGuard。
let options = {
hostname: proxy.hostname,
port: proxy.port || 80,
path: target.href,
headers:
{
"Proxy-Authorization": "Basic " + key,
"Host" : target.hostname
}
}
this.http.request("GET", target.href, options).subscribe((data:any) => {
console.log("target:", data);
});
}
我也试过这个,但是这个和以前的结果是 CORS 错误。同样在第二种方法中,我得到了关于我不应该设置标头代理授权和主机的信息。
我还尝试在邮递员中复制此请求,但没有任何标头,并且返回了有关我的 IP 地址错误的错误消息,而不仅仅是像以前那样的 CORS。
感谢帮助 :)