Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can I request use a socksv5 #636

Open
shangxinbo opened this issue Jan 6, 2017 · 7 comments
Open

how can I request use a socksv5 #636

shangxinbo opened this issue Jan 6, 2017 · 7 comments

Comments

@shangxinbo
Copy link

@shangxinbo shangxinbo commented Jan 6, 2017

const http = require('http');
const socks = require('socksv5');
http.get({ 
   hostname: 'google.com',
   port: 80,
   agent: new socks.HttpAgent({
          proxyHost: config.host,
          proxyPort: tcpPorts[i],
          auths: [socks.auth.None()]
    })
},function(res){
console.log(res);
})

when I use http request it can get the response,But when I use axios, it throw a error like this

    axios.request({
        url:'http://www.google.com',
        httpAgent: new socks.HttpAgent({
            proxyHost: config.host,
            proxyPort: tcpPorts[i],
            auths: [socks.auth.None()]
        })
    })
    .then(function(res){
        console.log(res);
    })
    .catch(function(err){
        console.log(err);
    })

I got the agent like this

{
  domain: null,
  _events: { free: [Function] },
  _eventsCount: 1,
  _maxListeners: undefined,
  defaultPort: 443,
  protocol: 'https:',
  options:
   { auths: [ [Object] ],
     proxyPort: 10086,
     proxyHost: '127.0.0.1',
     path: null },
  requests: {},
  sockets: {},
  freeSockets: {},
  keepAliveMsecs: 1000,
  keepAlive: false,
  maxSockets: Infinity,
  maxFreeSockets: 256 }
@rubennorte

This comment has been minimized.

Copy link
Member

@rubennorte rubennorte commented Jan 6, 2017

Could you provide information about the error that is throwing?

@shangxinbo

This comment has been minimized.

Copy link
Author

@shangxinbo shangxinbo commented Jan 7, 2017

{ Error: connect ETIMEDOUT 8.7.198.45:443
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
  code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  address: '8.7.198.45',
  port: 443,
  config:
   { adapter: [Function: httpAdapter],
     transformRequest: { '0': [Function: transformRequest] },
     transformResponse: { '0': [Function: transformResponse] },
     timeout: 0,
     xsrfCookieName: 'XSRF-TOKEN',
     xsrfHeaderName: 'X-XSRF-TOKEN',
     maxContentLength: -1,
     validateStatus: [Function: validateStatus],
     headers:
      { Accept: 'application/json, text/plain, */*',
        'User-Agent': 'axios/0.15.3' },
     method: 'get',
     url: 'https://www.google.com.hk',
     httpAgent:
      TunnelingAgent {
        options: [Object],
        proxyOptions: [Object],
        maxSockets: Infinity,
        requests: [],
        sockets: [],
        _events: [Object],
        _eventsCount: 1,
        request: [Function],
        createSocket: [Function: createSecureSocket] },
     data: undefined },
  response: undefined }
@c0b

This comment has been minimized.

Copy link

@c0b c0b commented Dec 13, 2017

also hit the issue with socks5, from https://github.com/mscdex/socksv5 I can create by new socks.HttpAgent({ ... }) make it work with node builtin http request, but with this axios.request httpAgent, it seems ignoring the proxy; does anyone have progress here?

@Khaledgarbaya Khaledgarbaya mentioned this issue Feb 5, 2018
11 of 48 tasks complete
@dzcpy

This comment has been minimized.

Copy link

@dzcpy dzcpy commented Feb 4, 2019

Any updates? Really need to use socksv5 with axios..

@jiangfb

This comment has been minimized.

@Dj-jom2x

This comment has been minimized.

Copy link

@Dj-jom2x Dj-jom2x commented Jul 27, 2019

@jiangfb thats not working i think , if you tried to check make some api that gets your ip it will still show your local ip

@denysonique

This comment has been minimized.

Copy link

@denysonique denysonique commented Sep 1, 2019

@jiangfb thats not working i think , if you tried to check make some api that gets your ip it will still show your local ip

It works, make sure you specify both httpsAgent and httpAgent options

    import { default as axios_ } from 'axios'
    let httpsAgent =  new SocksProxyAgent(proxyOptions)
    let httpAgent = httpsAgent
    axios = axios_.create({httpsAgent, httpAgent})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.