Node fetch / axios
Node 中纯 HTTP 请求(不用无头浏览器)的两大主流栈。
现代:undici(内置 fetch)
Node 18+ 的 fetch 来自 undici。要走 HTTP-CONNECT 代理需 undici 的 ProxyAgent:
npm i undiciimport { fetch, ProxyAgent } from "undici";
const agent = new ProxyAgent(
"http://helo_s1a2b3c4d5e-type-res-region-us:PASSWORD@gate.helodata.io:7777"
);
const res = await fetch("https://ipv4.icanhazip.com", { dispatcher: agent });
console.log((await res.text()).trim());
console.log("Exit IP:", res.headers.get("x-helodata-exit-ip"));ISP 把 URL 改为 http://helo_s1a2b3c4d5e:PASSWORD@198.51.100.42:8000。
SOCKS5 + undici
npm i socks-proxy-agentimport { SocksProxyAgent } from "socks-proxy-agent";
import { fetch } from "undici";
const agent = new SocksProxyAgent(
"socks5://helo_s1a2b3c4d5e-type-res-region-us:PASSWORD@gate.helodata.io:7777"
);
const res = await fetch("https://ipv4.icanhazip.com", { dispatcher: agent });axios
调用时务必
proxy: false,否则 axios 会用env推断又一次代理,干扰你设的 agent。
ISP 轮换
粘性会话(住宅)
验证
常见陷阱
undici的HTTP_PROXY环境变量模式 — 1.x 之前不识别环境变量,请显式用ProxyAgent。axios +
proxy: { host, port }— 这种写法不走 HTTP-CONNECT,会改写请求并破坏 HTTPS。请总用httpAgent/httpsAgent。连接复用 —
undici.Agent(默认 dispatcher)会池化连接;每请求新建ProxyAgent会失去池。ISP 场景每个 IP 共享一个 agent。
最后更新于
这有帮助吗?