sending http request with proxy ip in node.js

Viewed 137

I am trying to send an http get request from a different ip, such as hardcoding the proxy ip to use. I have a working http get request in node.js:

  const https = require('https')
    
      //get access token
      let accessToken = await spotifyAuth.getAccessToken();
      
      //create data
      const data = JSON.stringify({
        offset: 0,
      })

      //create options data obj
      const options = {
        hostname: 'api.spotify.com',
        path: '/v1/artists/1XqqyIQYMonHgllb1uysL3/albums',
        method: 'GET',
        headers: {
          'Authorization': 'Bearer ' + accessToken,
        },
      }

      const req = https.request(options, res => {
        console.log(`proxyiprequest() statusCode: ${res.statusCode}`)
        res.on('data', d => {
          process.stdout.write(d)
        })
      })
      
      req.on('error', error => {
        console.error('proxyiprequest() err=', error)
      })
      
      req.write(data)
      req.end()

So I'm trying to add an https proxy ip address/port combo I found from here like so:

      //create options data obj
      const options = {
        host: "220.135.165.38",
        port: 8080,

        hostname: 'api.spotify.com',
        path: '/v1/artists/1XqqyIQYMonHgllb1uysL3/albums',
        method: 'GET',
        headers: {
          'Authorization': 'Bearer ' + accessToken,
        },
      }

Would this method work? If I run the request it errors out like:

proxyiprequest() err= { Error: write EPROTO 18:error:1B:SSL routines:ssl3_get_record:wrong version number:../ssl/record/ssl3_record.c:331:

    at WriteWrap.afterWrite [as oncomplete] (net.js:789:14) errno: 'EPROTO', code: 'EPROTO', syscall: 'write' }
0 Answers
Related