Node.js语言如何接入代码Demo
本示例演示如何使用 IPWO 动态住宅代理 通过 账密认证方式 在 Node.js 中发送 HTTP 请求
// 引入 node-fetch,用于发送 HTTP 请求
import fetch from 'node-fetch';
// 引入 https-proxy-agent,用于创建代理对象
import createHttpsProxyAgent from 'https-proxy-agent'
// 设置IPWO的子账号
const username = 'username_custom_zone_us';
// 设置IPWO子账号的密码
const password = 'password';
// 设置 IPWO 代理服务器的地址及端口
const proxy = 'us.ipwo.net:7878'
// 创建一个代理对象,包含了代理认证信息(用户名:密码@IP:端口)
const agent = createHttpsProxyAgent(
\`http://${username}:${password}@${proxy}\`
);
// 发送 GET 请求到目标网址(此处以 ipinfo.io 为例)
const response = await fetch('http://ipinfo.io', {
method: 'get',
agent: agent, // 使用刚才创建的代理对象
});
// 输出响应内容,通常返回 IP 信息
console.log(await response.text());