Proxy in Node.js einrichten (Axios & natives Fetch)
Aktualisiert:
Die Standardoption proxy: { host, port } in Axios schlägt bei https://-Zielen fehl, da sie keinen HTTP CONNECT-Tunnel aushandelt. Um Anfragen in Node.js und TypeScript zuverlässig über authentifizierte HTTP(S)-Proxys von VinaProxy zu leiten, übergeben Sie einen HttpsProxyAgent (https-proxy-agent) an Axios oder einen undici.ProxyAgent-Dispatcher an das native Node fetch().
new HttpsProxyAgent('http://user:pass@ip:port')- 1 IP40.000 ₫
- 5+ IPs35.000 ₫
- 10+ IPs25.000 ₫
- 20+ IPs25.000 ₫
- 50+ IPs25.000 ₫
- 100+ IPs25.000 ₫
- 200+ IPs25.000 ₫
- 500+ IPs25.000 ₫
- 1000+ IPs22.000 ₫
- 2000+ IPs20.000 ₫
- 1 IP40.000 ₫
- 5+ IPs35.000 ₫
- 10+ IPs25.000 ₫
- 20+ IPs25.000 ₫
- 50+ IPs25.000 ₫
- 100+ IPs25.000 ₫
- 200+ IPs25.000 ₫
- 500+ IPs25.000 ₫
- 1000+ IPs22.000 ₫
- 2000+ IPs20.000 ₫
Proxy-Konfiguration: Axios vs. natives Node.js fetch()
Beide Bibliotheken verarbeiten standardmäßige http://user:pass@ip:port-URLs aus Ihrem VinaProxy-Dashboard problemlos:
| HTTP-Client | NPM-Paket | Empfohlener Code-Ausschnitt |
|---|---|---|
| Axios | npm i https-proxy-agent | axios.get(url, { httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port'), proxy: false }) |
Natives 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' }) } }) |
Connection-Pooling und Timeout-Best-Practices in Node.js
- Setzen Sie in Axios neben
httpsAgentimmerproxy: false, damit eventuelleHTTP_PROXY-Umgebungsvariablen des Systems ignoriert werden - Erzeugen Sie
HttpsProxyAgentoderProxyAgentaußerhalb von Schleifen nur einmal pro Proxy-IP, um persistente TCP-Keep-Alive-Sockets effizient wiederzuverwenden - Exportieren Sie Ihre VinaProxy-Proxyliste über unseren Proxy-Format-Konverter direkt als JSON-Array zur einfachen Einbindung
Schritt für Schritt
- 1
https-proxy-agent (oder undici) installieren
Führen Sie
npm install axios https-proxy-agentin Ihrem Node.js-Projektordner aus. - 2
HttpsProxyAgent-Instanz erstellen
Initialisieren Sie
const agent = new HttpsProxyAgent('http://user:pass@ip:port');mit Ihren VinaProxy-Zugangsdaten. - 3
httpsAgent und proxy: false an Axios übergeben
Rufen Sie
const res = await axios.get('https://vinaproxy.com/api/my-ip', { httpsAgent: agent, proxy: false, timeout: 10000 });auf. - 4
Ausgangs-IP verifizieren
Geben Sie
res.datain der Konsole aus, um die erfolgreiche Weiterleitung über Ihre dedizierte Proxy-IP zu bestätigen.
Häufig gestellte Fragen
Warum scheitert die Standardeinstellung proxy: { host, port, auth } in Axios bei HTTPS-URLs?
Die integrierte Proxy-Konfiguration von Axios sendet einen unverschlüsselten HTTP-Request anstelle eines HTTP CONNECT-TLS-Tunnels. Die Übergabe von httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port') zusammen mit proxy: false behebt dieses Problem.
Wie wird ein Proxy mit nativem fetch() in Node.js 18/20/22 verwendet?
Importieren Sie ProxyAgent aus undici und übergeben Sie { dispatcher: new ProxyAgent('http://user:pass@ip:port') } im Options-Objekt an fetch().
Kann ich meine Proxyliste für Node.js in JSON umwandeln?
Ja. Fügen Sie Ihre ip:port:user:pass-Zeilen in unseren kostenlosen Proxy-Format-Konverter ein und wählen Sie JSON als Ausgabeformat.
Verstärken Sie Ihre Node.js-Backends & Scraper mit statischen IPs
Dedizierte IPv4- und statische ISP-Proxys ohne Datenlimits sofort in 7 Ländern verfügbar.
Node.js-Proxys kaufen