代理选项不工作在请求模块的nodejs

Proxy option not working in request module of nodejs

本文关键字:模块 nodejs 请求 选项 工作 代理      更新时间:2023-09-26

当我尝试用nodejs执行代码时,它立即给出错误,甚至不处理用代理执行url,但是当我删除代理选项时,它可以工作。以下是我使用代理访问任何Url的代码:

request({
     headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Accept-Language': 'en-US,en;q=0.5',
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36',
     //  'Cookie': cookieReq
     },
     uri: 'www.website.com',
     method: 'GET',
     proxy: 192.12.31.12:3128
  }, function (error, response, html) {
       if (!error && response.statusCode == 200) {
          // final operations
          fs.writeFile('eight.html', html,  function(err) {
              if (err) {
                 return console.error(err);
              }
          });
       }
 });

Try
proxy: "http://192.12.31.12:3128"
而不是
proxy: 192.12.31.12:3128