በ Node.js ውስጥ ፕሮክሲ እንዴት እንደሚዋቀር (Axios እና Native Fetch)
Updated:
የ Axios አብሮ የተሰራ proxy: { host, port } አማራጭ የ HTTP CONNECT ዋሻ ባለመክፈቱ በ https:// ዒላማዎች ላይ አይሰራም። የ Node.js እና TypeScript ጥያቄዎችን በ VinaProxy ማረጋገጫ ባላቸው HTTP(S) ፕሮክሲዎች በኩል በተገቢው መንገድ ለማስተላለፍ HttpsProxyAgent (https-proxy-agent) ለ Axios ወይም undici.ProxyAgent dispatcher ለ Node native fetch() ያስተላልፉ።
new HttpsProxyAgent('http://user:pass@ip:port')- 1 IP₫40,000
- 5+ IPs₫35,000
- 10+ IPs₫25,000
- 20+ IPs₫25,000
- 50+ IPs₫25,000
- 100+ IPs₫25,000
- 200+ IPs₫25,000
- 500+ IPs₫25,000
- 1000+ IPs₫22,000
- 2000+ IPs₫20,000
- 1 IP₫40,000
- 5+ IPs₫35,000
- 10+ IPs₫25,000
- 20+ IPs₫25,000
- 50+ IPs₫25,000
- 100+ IPs₫25,000
- 200+ IPs₫25,000
- 500+ IPs₫25,000
- 1000+ IPs₫22,000
- 2000+ IPs₫20,000
የ Axios እና የ Node.js native fetch() ፕሮክሲ ውቅር ንጽጽር
ሁለቱም ላይብረሪዎች ከእርስዎ የ VinaProxy ዳሽቦርድ መደበኛ የ http://user:pass@ip:port ዩአርኤሎችን ይቀበላሉ፦
| የ HTTP ደንበኛ | ፓኬጅ | የሚመከር የኮድ ቅንጭብ |
|---|---|---|
| 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' }) } }) |
በ Node.js ውስጥ የግንኙነት ክምችት (connection pooling) እና የጊዜ ገደብ ምርጥ ልምዶች
- Axios እርስ በርስ የሚጋጩ የስርዓት
HTTP_PROXYየአካባቢ ተለዋዋጮችን ችላ እንዲል ሁልጊዜ ከhttpsAgentጎን ለጎንproxy: falseያዘጋጁ - ቀጣይነት ያላቸውን የ keep-alive ሶኬቶች በድጋሚ ለመጠቀም ከእርስዎ loop ውጭ ለአንድ ፕሮክሲ IP አንድ ጊዜ
HttpsProxyAgentወይምProxyAgentይፍጠሩ - የእኛን Proxy Format Converter በመጠቀም የ VinaProxy ፕሮክሲ ዝርዝርዎን በቀጥታ እንደ JSON ድርድር ይላኩ
ደረጃ በደረጃ
- 1
https-proxy-agent (ወይም undici) ይጫኑ
በእርስዎ Node.js ፕሮጀክት ውስጥ
npm install axios https-proxy-agentያሂዱ። - 2
የ HttpsProxyAgent instance ይፍጠሩ
የእርስዎን የ VinaProxy ምስክርነቶች በመጠቀም
const agent = new HttpsProxyAgent('http://user:pass@ip:port');ያስጀምሩ። - 3
httpsAgent እና proxy: false ን ለ Axios ያስተላልፉ
const res = await axios.get('https://vinaproxy.com/api/my-ip', { httpsAgent: agent, proxy: false, timeout: 10000 });ን ይጥሩ። - 4
የመውጫውን IP ያረጋግጡ
ምላሹ በተለየው ፕሮክሲ IPዎ በኩል መምጣቱን ለማረጋገጥ
res.dataን ይመዝግቡ።
ተደጋግመው የሚጠየቁ ጥያቄዎች
የ Axios ነባሪ `proxy: { host, port, auth }` በ HTTPS ዩአርኤሎች ላይ ለምን አይሰራም?
የ Axios አብሮ የተሰራ የፕሮክሲ ውቅር የ HTTP CONNECT TLS ዋሻ ከመክፈት ይልቅ ተራ የ HTTP ጥያቄ ይልካል። httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port') ን ከ proxy: false ጋር መጠቀም ይህንን ችግር ይፈታዋል።
በ Node.js 18/20/22 ውስጥ ፕሮክሲን ከ native `fetch()` ጋር እንዴት መጠቀም እችላለሁ?
ProxyAgent ን ከ undici ያስመጡ እና በ fetch() የአማራጮች ነገር ውስጥ { dispatcher: new ProxyAgent('http://user:pass@ip:port') } ያስገቡ።
የፕሮክሲ ዝርዝሬን ለ Node.js ወደ JSON መቀየር እችላለሁ?
አዎ—የእርስዎን ip:port:user:pass መስመሮች በነጻው Proxy Format Converter ውስጥ ይለጥፉ እና የ JSON ውጤትን ይምረጡ።
የ Node.js ባክኤንዶችዎን እና ስክራፐሮችዎን በስታቲክ አይፒዎች ያጎልብቱ
በ 7 አገሮች ውስጥ ያልተገደበ ፈጣን Dedicated IPv4 እና Static ISP ፕሮክሲዎች።
የ Node.js ፕሮክሲዎችን ይግዙ