node.js - 我如何使用带有请求或任何东西的node.js通过http代理通过https获取数据

标签 node.js proxy https

我有一个 polipo 实例在端口 8123 上的 liunx 服务器上运行 我需要通过此代理服务器在 Node 内部使用 https 发出 get 和 post 请求。 我该怎么做。

顺便说一句,proxychains 不足以完成此任务,因为它似乎将请求放入队列中,而不是一次打开多个连接 我可以使用 socks 来完成我的任务,但 tsocks 似乎根本不起作用

其他一些帖子建议通过 http 进行传输

没有

<小时/>
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET https://www.google.com/accounts/OAuthGetRequestToken HTTP/1.1

HTTP/1.1 400 Couldn't parse URL
Connection: keep-alive
Date: Tue, 02 Aug 2011 23:50:34 GMT
Content-Type: text/html
Content-Length: 487
Expires: 0
Cache-Control: no-cache
Pragma: no-cache

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>Proxy error: 400 Couldn't parse URL.</title>
</head><body>
<h1>400 Couldn't parse URL</h1>
<p>The following error occurred while trying to access <strong>https://www.google.com/accounts/OAuthGetRequestToken</strong>:<br><br>
<strong>400 Couldn't parse URL</strong></p>
<hr>Generated Tue, 02 Aug 2011 19:50:34 EDT by Polipo on <em>ubuntu:8123</em>.
</body></html>

Connection closed by foreign host.
<小时/>

我该如何完成这项工作

最佳答案

由于您没有显示任何代码,因此很难确定您的问题。不过,试试这个:

var http = require("http");
var options = {
  host: "localhost",
  port: 8118,
  path: "http://check.torproject.org",
  method: 'POST',
  headers: {
    Host: "http://check.torproject.org",
  }
};
var req = https.request(options, function(res) {
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
});

请注意,我们将完整的目标 URL 传递到路径和主机 header 中。

关于node.js - 我如何使用带有请求或任何东西的node.js通过http代理通过https获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6920167/

相关文章:

javascript - 使用 Node/Express 正确处理错误

java - Maven:尽管 settings.xml 具有使用 HTTPS 配置的存储库,但无法检索插件描述符和对等体未经过身份验证的错误

java - Apache CommonsVFS 连接到 https 服务器

java - ActiveMQ、SSL 和传输连接器

javascript - 客户端如何知道发出是否失败? socket.emit() 有回调吗?

node.js - 迁移回滚需要写反向操作吗?

javascript - 如何创建异步方法的同步版本?

node.js - 无法导入代理的类型

java - CGLIB 无法拦截父类(super class)/超接口(interface)中的方法

go - 代理处理函数中 []byte 的字符串表示形式