简体   繁体   English

代理选项在Node.js的请求模块中不起作用

[英]Proxy option not working in request module of nodejs

When I try to execute the code with nodejs , it immediately gives error and not even process to execute the url with proxy, but when I remove the proxy option it works. 当我尝试使用nodejs执行代码时,它立即给出错误,甚至没有执行代理程序执行url的过程,但是当我删除proxy选项时,它就起作用了。 Following is my code for hitting any Url using proxy: 以下是我使用代理命中任何网址的代码:

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"
instead of 代替
proxy: 192.12.31.12:3128

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM