For the complete documentation index, see llms.txt. This page is also available as Markdown.

Node fetch / axios

Node 中纯 HTTP 请求(不用无头浏览器)的两大主流栈。

现代:undici(内置 fetch)

Node 18+ 的 fetch 来自 undici。要走 HTTP-CONNECT 代理需 undiciProxyAgent

npm i undici
import { 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-agent
import { 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 轮换

粘性会话(住宅)

验证

常见陷阱

  • undiciHTTP_PROXY 环境变量模式 — 1.x 之前不识别环境变量,请显式用 ProxyAgent

  • axios + proxy: { host, port } — 这种写法走 HTTP-CONNECT,会改写请求并破坏 HTTPS。请总用 httpAgent/httpsAgent

  • 连接复用undici.Agent(默认 dispatcher)会池化连接;每请求新建 ProxyAgent 会失去池。ISP 场景每个 IP 共享一个 agent。

最后更新于

这有帮助吗?