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

Use proxy to send request #13

Open
fordca opened this issue Mar 12, 2024 · 3 comments
Open

Use proxy to send request #13

fordca opened this issue Mar 12, 2024 · 3 comments

Comments

@fordca
Copy link

fordca commented Mar 12, 2024

Hi, thanks for this repo to use 2captcha conveniently.

I wonder if there is a way to config a proxy to use solver, because my code run behind a work NAT and can't connect to 2captcha.com directly
I have been looked for the code and there is no proxy config for init solver.

Is there a way to solve my problem that I didn't found OR there is no proxy's config for now?

@dzmitry-duboyski
Copy link
Owner

@fordca at the moment, the proxy can be used along with the rest of the captcha parameters, as described here.

Example:

solver.recaptcha({
  pageurl: 'https://2captcha.com/demo/recaptcha-v2',
  googlekey: '6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u',
  proxy: "login:password@1.2.3.4:8888", // The (Username : Password @ Address : Port) of our chosen proxy
  proxytype: "http" // The 'Type' of proxy, http, https, socks4, socks5.
})
.then((res) => {
  console.log(res)
})
.catch((err) => {
  console.error(err.message)
})

@kratzky
Copy link

kratzky commented Apr 29, 2024

Is there a way to solve my problem that I didn't found OR there is no proxy's config for now?

2captcha-ts uses node-fetch that doesn't support proxies.

I think you can setup a proxy-agent in your project and it should be used by node-fetch for the API calls. Never tried by myself but it worth to try for your case.

@wh1t3h47
Copy link

wh1t3h47 commented Jun 3, 2024

Hello
Node fetch supports proxies (tested and it works)
Although, yes, you need an external agent

For example:

import { SocksProxyAgent } from 'socks-proxy-agent';

const agent = new SocksProxyAgent('socks5h://127.0.0.1:9050');


await fetch('https://google.com', {
        agent,
        method: 'POST',
        body: {}
        headers,
      })
 }

I tested and it works, don't know about DNS leaks tho, but socks5h should have it resolving DNS in socks if the socks-proxy-agent works as supposed. I suggest using wireshark to check it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants