Indlela yokusetha i-proxy ku-Node.js (Axios ne-Native Fetch)
Updated:
Inketho eyakhelwe ngaphakathi ye-Axios ethi proxy: { host, port } yehluleka kokuhlosiwe kwe-https:// ngoba ayivuli umhubhe we-HTTP CONNECT. Ukuze uqondise izicelo ze-Node.js ne-TypeScript kahle kuma-proxy e-HTTP(S) agunyaziwe e-VinaProxy, dlulisela i-HttpsProxyAgent (https-proxy-agent) ku-Axios noma i-dispatcher ye-undici.ProxyAgent ku-fetch() yomdabu ye-Node.
new HttpsProxyAgent('http://user:pass@ip:port')- 1 IP₫40,000
- 5+ ama-IP₫35,000
- 10+ ama-IP₫25,000
- 20+ ama-IP₫25,000
- 50+ ama-IP₫25,000
- 100+ ama-IP₫25,000
- 200+ ama-IP₫25,000
- 500+ ama-IP₫25,000
- 1000+ ama-IP₫22,000
- 2000+ ama-IP₫20,000
- 1 IP₫40,000
- 5+ ama-IP₫35,000
- 10+ ama-IP₫25,000
- 20+ ama-IP₫25,000
- 50+ ama-IP₫25,000
- 100+ ama-IP₫25,000
- 200+ ama-IP₫25,000
- 500+ ama-IP₫25,000
- 1000+ ama-IP₫22,000
- 2000+ ama-IP₫20,000
Ukucushwa kwe-proxy: Axios vs. fetch() yomdabu ku-Node.js
Zombili izilabhulali zamukela ama-URL ajwayelekile e-http://user:pass@ip:port avela kudeshibhodi yakho ye-VinaProxy:
| Iklayenti le-HTTP | Iphakethe | Ucezu Lwekhodi Olunconyiwe |
|---|---|---|
| Axios | npm i https-proxy-agent | axios.get(url, { httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port'), proxy: false }) |
Native fetch (Node 18+) | npm i undici | fetch(url, { dispatcher: new ProxyAgent('http://user:pass@ip:port') }) |
| Got | npm i hpagent | got(url, { agent: { https: new HttpsProxyAgent({ proxy: 'http://user:pass@ip:port' }) } }) |
Izindlela ezingcono kakhulu zokuhlanganisa ukuxhumana nesikhathi sokuphela ku-Node.js
- Hlala ubeka u-
proxy: falseeceleni kwe-httpsAgentku-Axios ukuze i-Axios inganaki okuguquguqukayo kwendawo yesistimu okungqubuzanayo kwe-HTTP_PROXY - Qalisa i-
HttpsProxyAgentnoma i-ProxyAgentkanye nge-IP ngayinye ye-proxy ngaphandle kweluphu yakho ukuze uphinde usebenzise amasokhethi ahlala ekhona e-keep-alive - Khipha uhlu lwakho lwe-proxy ye-VinaProxy ngqo njenge-JSON array usebenzisa i-Proxy Format Converter yethu
Isinyathelo ngesinyathelo
- 1
Faka i-https-proxy-agent (noma i-undici)
Gijima
npm install axios https-proxy-agentkuphrojekthi yakho ye-Node.js. - 2
Dala isibonelo se-HttpsProxyAgent
Qalisa
const agent = new HttpsProxyAgent('http://user:pass@ip:port');usebenzisa imininingwane yakho yokungena ye-VinaProxy. - 3
Dlulisela i-httpsAgent kanye no-proxy: false ku-Axios
Biza
const res = await axios.get('https://vinaproxy.com/api/my-ip', { httpsAgent: agent, proxy: false, timeout: 10000 });. - 4
Qinisekisa i-IP yokuphuma
Bhalisa
res.dataukuze uqinisekise ukuthi impendulo ifike nge-IP yakho ye-proxy ezinikele.
Imibuzo evame ukubuzwa
Kungani i-`proxy: { host, port, auth }` ezenzakalelayo ye-Axios yehluleka kuma-URL e-HTTPS?
Ukucushwa kwe-proxy eyakhelwe ngaphakathi kwe-Axios kuthumela isicelo se-HTTP esivamile esikhundleni sokuvula umhubhe we-TLS we-HTTP CONNECT. Ukusebenzisa i-httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port') ene-proxy: false kulungisa lokhu.
Ngiyisebenzisa kanjani i-proxy ene-`fetch()` yomdabu ku-Node.js 18/20/22?
Ngenisa i-ProxyAgent kusuka ku-undici bese udlulisela i-{ dispatcher: new ProxyAgent('http://user:pass@ip:port') } entweni yezinketho ze-fetch().
Ngingakwazi ukuguqulela uhlu lwami lwe-proxy ku-JSON ye-Node.js?
Yebo—namathisela imigqa yakho ye-ip:port:user:pass ku-Proxy Format Converter yethu yamahhala bese ukhetha okukhiphayo kwe-JSON.
Nika amandla ama-backend akho e-Node.js nama-scraper ngama-IP angaguquki
Ama-proxy asheshayo angenamkhawulo e-Dedicated IPv4 kanye ne-Static ISP emazweni angu-7.
Thenga Ama-Proxy e-Node.js