如何使用 Node.js 服务器使用 QuotaGuard 设置角度代理
我有一个在heroku上运行的角度应用程序,它需要访问只能通过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 的静态 IP 地址(不是 Proximo)在 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。
感谢您的帮助:)
I have an angular application running on heroku, that needs to access external API that is accesible only through IP configured in QuotaGuard.
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);
});
}
I saw here: Static IP Address with Heroku (not Proximo) that setting up a proxy in ruby is just a configuration for httpClient, how does it work in Angular? I'd like to use proxy in mine requests, as my heroku app has a dynamic IP and only way to use static is 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);
});
}
I've tried this as well, however this and previous results in CORS error. Also in second approach I'm getting information about the fact that I shouldn't set headers Proxy-authorization and Host.
I've tried also to replicate this requests in postman with just none headers and I've been returned with error message about mine IP address being wrong, not just CORS like previously.
Thanks for help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,直到现在我才看到这一点,以下是如何使其工作:
标准 Node.js HTTPS 模块不能很好地处理通过代理发出的请求。如果您需要访问 HTTPS API,我们建议使用请求模块(npm install request)。
如果这仍然给您带来麻烦,请访问我们的支持网站,我们将帮助您解决问题。
Sorry I didn't see this until now, here's how to make it work:
The standard Node.js HTTPS module does not handle making requests through a proxy very well. If you need to access an HTTPS API we recommend using the Request module (npm install request).
If that's still giving you trouble, hit us up at our Support site and we'll help figure it out with you.