This commit is contained in:
nm1 2026-11-04 00:33:23 +05:30
commit 74ae93a96e

View file

@ -0,0 +1,40 @@
using proxy with fetch
https://www.zenrows.com/blog/node-fetch-proxy#how-to-use-proxy-with-node-fetch
for username and password
https://github.com/TooTallNate/proxy-agents/issues/12
```js
const fetch = require('node-fetch');
const proxyUrl = 'http://proxyserver:port';
const proxyOptions = {
proxy: proxyUrl,
headers: {
'Proxy-Authorization': 'Basic ' + Buffer.from('username:password').toString('base64')
}
};
fetch('http://url-to-fetch', proxyOptions)
.then(response => response.text())
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error:', error);
});
```
Same with curl
`curl -x http://proxyserver:port --proxy-user username:password http://url-to-fetch`
for socks5
`curl -v --socks5 127.0.0.1:1080 https://icanhazip.com`
replace with socks4 for socks4