Node.js တွင် Proxy ချိတ်ဆက်သတ်မှတ်နည်း (Axios နှင့် Native Fetch)
Updated:
Axios ၏ မူရင်းပါဝင်သော proxy: { host, port } ရွေးချယ်မှုသည် HTTP CONNECT လှိုဏ်ခေါင်းကို မဖွင့်ပေးသောကြောင့် https:// ပစ်မှတ်များတွင် အလုပ်မလုပ်ပါ။ Node.js နှင့် TypeScript တောင်းဆိုမှုများကို VinaProxy ၏ အထောက်အထားစိစစ်ထားသော HTTP(S) proxy များမှတစ်ဆင့် ချောမွေ့စွာ ဖြတ်သန်းပို့ဆောင်ရန် Axios သို့ HttpsProxyAgent (https-proxy-agent) ကို ပေးပို့ပါ သို့မဟုတ် မူရင်း Node fetch() သို့ undici.ProxyAgent dispatcher ကို ပေးပို့ပါ။
new HttpsProxyAgent('http://user:pass@ip:port')- 1 IP၄၀,၀၀၀ ₫
- 5+ IPs၃၅,၀၀၀ ₫
- 10+ IPs၂၅,၀၀၀ ₫
- 20+ IPs၂၅,၀၀၀ ₫
- 50+ IPs၂၅,၀၀၀ ₫
- 100+ IPs၂၅,၀၀၀ ₫
- 200+ IPs၂၅,၀၀၀ ₫
- 500+ IPs၂၅,၀၀၀ ₫
- 1000+ IPs၂၂,၀၀၀ ₫
- 2000+ IPs၂၀,၀၀၀ ₫
- 1 IP၄၀,၀၀၀ ₫
- 5+ IPs၃၅,၀၀၀ ₫
- 10+ IPs၂၅,၀၀၀ ₫
- 20+ IPs၂၅,၀၀၀ ₫
- 50+ IPs၂၅,၀၀၀ ₫
- 100+ IPs၂၅,၀၀၀ ₫
- 200+ IPs၂၅,၀၀၀ ₫
- 500+ IPs၂၅,၀၀၀ ₫
- 1000+ IPs၂၂,၀၀၀ ₫
- 2000+ IPs၂၀,၀၀၀ ₫
Axios နှင့် မူရင်း Node.js fetch() proxy ပြင်ဆင်သတ်မှတ်မှု နှိုင်းယှဉ်ချက်
လိုက်ဘရီနှစ်ခုစလုံးသည် သင်၏ VinaProxy ဒက်ရှ်ဘုတ်မှ ပုံမှန် http://user:pass@ip:port URL များကို လက်ခံပါသည်-
| HTTP Client | Package | အကြံပြုထားသော ကုဒ်နမူနာ |
|---|---|---|
| Axios | npm i https-proxy-agent | axios.get(url, { httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port'), proxy: false }) |
မူရင်း 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 နှင့် timeout ဆိုင်ရာ အကောင်းဆုံး လုပ်ဆောင်နည်းများ
- ပဋိပက္ခဖြစ်နိုင်သော စနစ်၏
HTTP_PROXYenvironment variables များကို Axios က လျစ်လျူရှုနိုင်ရန် Axios ရှိhttpsAgentနှင့်အတူproxy: falseကို အမြဲတမ်း သတ်မှတ်ပါ - အမြဲဖွင့်ထားသော keep-alive socket များကို ပြန်လည်အသုံးပြုနိုင်ရန် သင်၏ loop ပြင်ပတွင် proxy IP တစ်ခုလျှင်
HttpsProxyAgentသို့မဟုတ်ProxyAgentကို တစ်ကြိမ်သာ ဖန်တီးပါ - ကျွန်ုပ်တို့၏ Proxy Format Converter ကို အသုံးပြု၍ သင်၏ VinaProxy proxy စာရင်းကို JSON array အဖြစ် တိုက်ရိုက် ထုတ်ယူပါ
အဆင့်ဆင့် လုပ်ဆောင်ရန်
- 1
https-proxy-agent (သို့မဟုတ် undici) ကို ထည့်သွင်းပါ
သင်၏ Node.js ပရောဂျက်တွင်
npm install axios https-proxy-agentကို run ပါ။ - 2
HttpsProxyAgent instance တစ်ခု ဖန်တီးပါ
သင်၏ VinaProxy အထောက်အထားများကို အသုံးပြု၍
const agent = new HttpsProxyAgent('http://user:pass@ip:port');ကို initialize လုပ်ပါ။ - 3
Axios သို့ httpsAgent နှင့် proxy: false ကို ပေးပို့ပါ
const res = await axios.get('https://vinaproxy.com/api/my-ip', { httpsAgent: agent, proxy: false, timeout: 10000 });ကို ခေါ်ယူပါ။ - 4
Exit IP ကို စစ်ဆေးအတည်ပြုပါ
တုံ့ပြန်မှုသည် သင်၏ သီးသန့် proxy IP မှတစ်ဆင့် လာကြောင်း အတည်ပြုရန်
res.dataကို log ထုတ်ကြည့်ပါ။
မကြာခဏမေးလေ့ရှိသော မေးခွန်းများ
Axios ၏ မူရင်း `proxy: { host, port, auth }` သည် HTTPS URL များတွင် အဘယ်ကြောင့် အလုပ်မလုပ်သနည်း။
Axios ၏ မူရင်း proxy ပြင်ဆင်ချက်သည် HTTP CONNECT TLS လှိုဏ်ခေါင်းကို မဖွင့်ဘဲ ရိုးရိုး HTTP တောင်းဆိုမှုကို ပေးပို့သောကြောင့် ဖြစ်ပါသည်။ proxy: false နှင့်အတူ httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port') ကို အသုံးပြုခြင်းဖြင့် ၎င်းကို ဖြေရှင်းနိုင်ပါသည်။
Node.js 18/20/22 တွင် မူရင်း `fetch()` ဖြင့် proxy ကို မည်သို့ အသုံးပြုရမည်နည်း။
undici မှ ProxyAgent ကို import လုပ်ပြီး fetch() ၏ options object ထဲတွင် { dispatcher: new ProxyAgent('http://user:pass@ip:port') } ကို ထည့်သွင်းပေးပို့ပါ။
ကျွန်ုပ်၏ proxy စာရင်းကို Node.js အတွက် JSON သို့ ပြောင်းလဲနိုင်ပါသလား။
ပြောင်းလဲနိုင်ပါသည်—သင်၏ ip:port:user:pass လိုင်းများကို ကျွန်ုပ်တို့၏ အခမဲ့ Proxy Format Converter တွင် ထည့်သွင်းပြီး JSON output ကို ရွေးချယ်ပါ။
သင်၏ Node.js backend များနှင့် scraper များကို static IP များဖြင့် အားဖြည့်ပါ
နိုင်ငံပေါင်း 7 နိုင်ငံရှိ ကန့်သတ်မဲ့ အသုံးပြုနိုင်သော သီးသန့် IPv4 နှင့် Static ISP proxy များကို ချက်ချင်း ရယူလိုက်ပါ။
Buy Node.js Proxies