Fomba fametrahana proxy amin'ny Node.js (Axios sy Native Fetch)
Updated:
Tsy mandeha amin'ny tanjona https:// ny safidy anatiny proxy: { host, port } an'ny Axios satria tsy manokatra tonelina HTTP CONNECT izy. Mba handefasana tsara ny fangatahana Node.js sy TypeScript amin'ny alalan'ny proxy HTTP(S) misy fidirana VinaProxy, ampidiro ny HttpsProxyAgent (https-proxy-agent) amin'ny Axios na mpandefa undici.ProxyAgent amin'ny fetch() natoralin'ny Node.
new HttpsProxyAgent('http://user:pass@ip:port')- IP 1₫ 40,000
- IP 5+₫ 35,000
- IP 10+₫ 25,000
- IP 20+₫ 25,000
- IP 50+₫ 25,000
- IP 100+₫ 25,000
- IP 200+₫ 25,000
- IP 500+₫ 25,000
- IP 1000+₫ 22,000
- IP 2000+₫ 20,000
- IP 1₫ 40,000
- IP 5+₫ 35,000
- IP 10+₫ 25,000
- IP 20+₫ 25,000
- IP 50+₫ 25,000
- IP 100+₫ 25,000
- IP 200+₫ 25,000
- IP 500+₫ 25,000
- IP 1000+₫ 22,000
- IP 2000+₫ 20,000
Fampifanarahana proxy: Axios sy ny fetch() natoralin'ny Node.js
Samy manaiky URL mahazatra http://user:pass@ip:port avy amin'ny solaitrabe VinaProxy-nao ny tranomboky roa tonta:
| Mpanjifa HTTP | Package | Kaody atolotra |
|---|---|---|
| Axios | npm i https-proxy-agent | axios.get(url, { httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port'), proxy: false }) |
fetch natoraly (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' }) } }) |
Fomba fanao tsara indrindra amin'ny fifandraisana sy timeout amin'ny Node.js
- Ampifandraiso foana ny
proxy: falsemiaraka amin'nyhttpsAgentao amin'ny Axios mba tsy hiraharahan'ny Axios ireo variable tontolo iainanaHTTP_PROXYmifanipaka ao amin'ny rafitra - Amboary indray mandeha isaky ny IP proxy ivelan'ny loop ny
HttpsProxyAgentnaProxyAgentmba hampiasana indray ireo socket keep-alive maharitra - Aondrano mivantana ho array JSON ny lisitry ny proxy VinaProxy-nao amin'ny alalan'ny Proxy Format Converter-tsika
Tsikelikely
- 1
Mametraka https-proxy-agent (na undici)
Alefaso ao amin'ny tetikasa Node.js-nao ny
npm install axios https-proxy-agent. - 2
Mamorona ny instance HttpsProxyAgent
Atombohy ny
const agent = new HttpsProxyAgent('http://user:pass@ip:port');amin'ny fampiasana ny fidirana VinaProxy-nao. - 3
Alefaso amin'ny Axios ny httpsAgent sy proxy: false
Antsoy ny
const res = await axios.get('https://vinaproxy.com/api/my-ip', { httpsAgent: agent, proxy: false, timeout: 10000 });. - 4
Hamarino ny IP fivoahana
Asehoy amin'ny log ny
res.datamba hanamafisana fa nandalo tamin'ny IP proxy natokana ho anao ny valiny.
Fanontaniana matetika apetraka
Nahoana no tsy mandeha amin'ny URL HTTPS ny safidy mahazatra `proxy: { host, port, auth }` an'ny Axios?
Mandefa fangatahana HTTP tsotra ny fikirakirana proxy anatiny an'ny Axios fa tsy manokatra tonelina TLS HTTP CONNECT. Manitsy izany ny fampiasana ny httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port') miaraka amin'ny proxy: false.
Ahoana ny fampiasana proxy amin'ny `fetch()` natoraly ao amin'ny Node.js 18/20/22?
Ampidiro ny ProxyAgent avy amin'ny undici ary apetraho ao amin'ny safidin'ny fetch() ny { dispatcher: new ProxyAgent('http://user:pass@ip:port') }.
Azoko avadika ho JSON ho an'ny Node.js ve ny lisitry ny proxy-ko?
Eny—apetaho ao amin'ny Proxy Format Converter maimaim-poana anay ny andalana ip:port:user:pass-nao ary safidio ny endrika JSON.
Hamafiso amin'ny IP tsy miovaova ny backend sy scrapers Node.js-nao
Proxy IPv4 Natokana sy ISP Tsy Miovaova avy hatrany, tsy misy fetra, manerana firenena 7.
Mividiana Proxy Node.js