【问题标题】:How can I use an http proxy with node.js https?如何将 http 代理与 node.js https 一起使用?
【发布时间】:2013-05-27 15:48:06
【问题描述】:

我想使用标准 https 客户端从 node.js 发出 https 请求调用。但我无法直接从我的网络访问远程服务器,需要通过代理。

如何告诉 node.js 使用代理? 我尝试了以下post

{ path : 'https://api.xxx.com:8081/token';
host : 'proxy-us.xxxx.com';
port : 8082;
method : POST_METHOD;
headers : {
    'host':  "api.xxx.com:8081"
}

但从未到达

【问题讨论】:

  • 它是 HTTP 代理还是 SOCKS 代理?

标签: node.js https proxy


【解决方案1】:

我是Mikeal's request module 的忠实粉丝。它使 http 请求变得非常容易,并具有许多功能,例如代理支持、流式传输、表单、身份验证和 oauth 签名。这是一个代理示例:

var request = require('request');
request({'url':'https://api.xxx.com:8081/token',
         'proxy':'http://proxy-us.xxxx.com:8082'}, function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Print the google web page.
  }
})

【讨论】:

  • 对http很好,但我需要https requeqes
猜你喜欢
  • 2011-04-21
  • 2016-03-08
  • 2016-07-16
  • 1970-01-01
  • 2019-12-18
  • 2011-07-06
  • 1970-01-01
  • 1970-01-01
  • 2015-07-23
相关资源
最近更新 更多