nodejs request使用ss5代理

安装依赖

yarn add request socks5-https-client

代码

var request = require('request');
// var Agent = require('socks5-http-client/lib/Agent')
var Agent = require('socks5-https-client/lib/Agent');

request({
    url: 'https://www.instagram.com/',
    strictSSL: true,
    agentClass: Agent,
    agentOptions: {
        socksHost: '45.77.*2.9*',
        socksPort: 8080,
        socksUsername: 'test',
        socksPassword: '12345678'
    },
    headers: {
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36"
    }
}, function (err, res) {
    debugger
    console.log(err || res.body);
});

你可能感兴趣的:(nodejs request使用ss5代理)