添加代理时节点请求不起作用

时间:2019-03-18 11:34:41

标签: node.js http express proxy request

我使用npm Request命中了请求并获取数据。参见下文及其正常工作。

const Request = require('request');
   let option = {          
        url:'Request URL',
        method: 'GET',
        headers: headers
    };

    Request(options, function(error, response, body) {
      if (!error && response.statusCode == 200) {
        console.log({ error, response, body });
      } else {
        console.log('Error', error);
      }
    });

但是当我在代理请求中点击相同的URL时。

let option = {          
        url:'Request URL',
        method: 'GET',
        headers: headers,
        proxy: 'Proxy server details',
    };

    Request(options, function(error, response, body) {
      if (!error && response.statusCode == 200) {
        console.log({ error, response, body });
      } else {
        console.log('Error', error);
      }
    });

然后显示错误

Error: tunneling socket could not be established, statusCode=403
at ClientRequest.onConnect (/home/admin14/node_projects/bigmuskie/node_modules/tunnel-agent/index.js:166:19)
at Object.onceWrapper (events.js:277:13)
at ClientRequest.emit (events.js:189:13)
at Socket.socketOnData (_http_client.js:475:11)
at Socket.emit (events.js:189:13)
at addChunk (_stream_readable.js:284:12)
at readableAddChunk (_stream_readable.js:265:11)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) code: 'ECONNRESET' }

任何帮助将不胜感激。谢谢

0 个答案:

没有答案