簡體   English   中英

嘗試使用node.js 0.12代理HTTPS請求時出現EPROTO錯誤

[英]EPROTO error when trying to make a proxied HTTPS request with node.js 0.12

在較高的級別上,我嘗試使用Quota Guard Static與來自node.js應用程序的Heroku應用程序與IP受限的API進行通信。 該API具有自己的node.js客戶端實現,但在幕后僅是HTTP [S] api。 該庫在幕后使用了superagentsuperagent-proxy來執行實際的HTTP [S]請求。

在節點0.10中,一切正常。 在節點0.12中,我看到如下錯誤:

Error: write EPROTO 140735203734288:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:782:
    at exports._errnoException (util.js:746:11)
    at WriteWrap.afterWrite (net.js:775:14)

在io.js 2.02中,我看到了:

Error: write EPROTO    at Object.exports._errnoException (util.js:844:11)

如該答案所示,我在全球范圍內嘗試使用SSLv3,但這似乎沒有任何效果。

代理URL被指定為帶有端口9293的http URL。建議使用端口443 回答問題 ,但是由於代理提供程序對我來說是外部的,因此我無法更改它。

如何獲得代理請求以在節點0.12中工作?

Tim來自QuotaGuard。 這似乎是一個問題,這在superagent-proxy用於HTTPS請求的https-proxy-agent中表現出來,導致對錯誤端口上的安全端點的請求。

這是一個簡單的示例,應該通過端口443連接到Google。

var url = require('url');
var https = require('https');
var HttpsProxyAgent = require('https-proxy-agent');

// HTTP/HTTPS proxy to connect to
var proxy = process.env.QUOTAGUARDSTATIC_URL;
console.log('using proxy server %j', proxy);

// HTTPS endpoint for the proxy to connect to
var endpoint = process.argv[2] || 'https://www.google.com/';
console.log('attempting to GET %j', endpoint);
var opts = url.parse(endpoint);

// create an instance of the `HttpsProxyAgent` class with the proxy server information
var agent = new HttpsProxyAgent(proxy);
opts.agent = agent;
https.get(opts, function (res) {
  console.log('"response" event!', res.headers);
  res.pipe(process.stdout);
});

實際的請求是在端口80上發出的,因此Google拒絕了該請求。 這是HTTP標頭:

["Proxy-Authorization: Basic Xgat28sa78saBZZ \r\n", "Host: www.google.com:80\r\n", "Connection: close\r\n"]

修補版本上的相同示例正確連接到端口443,並且可以正常工作:

https://github.com/TooTallNate/node-https-proxy-agent/compare/master...timrwilliams:master

我懷疑上游發生了一些變化,這導致將錯誤的端口傳遞給https-proxy-agent,但是在Github問題上更適當地討論了這種類型的問題。

一個快速解決方案是切換為使用請求庫:

var request = require('request');

var options = {
    proxy: process.env.QUOTAGUARDSTATIC_URL,
    url: 'https://www.google.com/',
    headers: {
        'User-Agent': 'node.js'
    }
};

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    }
}

request(options, callback);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM