【问题标题】:How can I use proxies in Request-Promise requests?如何在 Request-Promise 请求中使用代理?
【发布时间】:2020-06-05 15:35:47
【问题描述】:

我正在尝试使用 HTTP 代理文件,为每个请求选择一个随机代理,然后使用 request-promise 库进行请求。

const rp = require('request-promise'),
    fs = require('fs')

var proxies = []

function sendR() {
    let proxy = getProxy()
    console.log('Got proxy ' + proxy)
    let requestThing = rp.defaults({
        method: 'GET',
        proxy: 'http://' + proxy
    })
    requestThing('http://server.test.ip:1234').then((body) => {
        console.log(body)
    })
}

function getProxy() {
    return proxies[Math.floor(Math.random() * proxies.length)]
}

fs.readFile('proxy.txt', (err, data) => {
    if (err) throw err
    proxies = data.toString().split("\n")
})

setTimeout(sendR, 1000)

我收到错误未处理的拒绝请求错误:错误:连接 ETIMEDOUT 1.1.1.1:80,我已经非常频繁地检查了所有代理。

【问题讨论】:

    标签: node.js proxy request request-promise proxies


    【解决方案1】:

    只是继续测试有效。这样做可以解决它。

    const rp = require('request-promise'),
        fs = require('fs')
    
    var proxies = []
    
    function sendR() {
        let proxy = getProxy()
        console.log('Got proxy ' + proxy)
        let requestThing = rp.defaults({
            method: 'GET',
            proxy: 'http://' + proxy,
            jar: true
        })
        requestThing('http://a').then((body) => {
            console.log(body)
        }).catch((e) => {
            console.log('Error with proxy ' + proxy)
        })
    }
    
    function getProxy() {
        return proxies[Math.floor(Math.random() * proxies.length)]
    }
    
    fs.readFile('proxy.txt', (err, data) => {
        if (err) throw err
        proxies = data.toString().split("\n")
    })
    
    setTimeout(() => {
        setInterval(sendR, 50)
    }, 1000)
    

    我想问题出在代理上,因为最终测试了很多代理。我的错。 https://i.imgur.com/h5WOyCN.png

    【讨论】:

      猜你喜欢
      • 2016-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多