分享页面
拖动logo到书签栏,立即收藏青果网络
控制台
|
登录/注册
子
用户在实名认证前无法开通业务
充值
未支付订单
未完成工单
未读消息
会员中心
退出登录
文档中心
产品介绍
使用指南
开发者指南
API接口
代码示例
常见问题
账户中心
查询
产品介绍
短效代理
产品介绍
提取方式
资源池
使用指南
API接口
隧道代理
产品介绍
使用指南
独享代理
产品介绍
地区锁功能
使用指南
API接口
长效代理
产品介绍
使用指南
API接口
短效代理(全球HTTP)
产品介绍
提取方式
资源池
使用指南
API接口
隧道代理(全球HTTP)
产品介绍
资源池
使用指南
长效代理(全球HTTP)
产品介绍
使用指南
API接口
独享代理(全球HTTP)
产品介绍
使用指南
API接口
短效代理
产品介绍
提取方式
弹性提取
按量提取
均匀提取
通道提取
企业定制
资源池
中转池
隧道池
使用指南
使用指南
开发者指南
API接口
弹性提取
API接口介绍
提取IP
查询余额
查询资源地区
按量提取
API接口介绍
提取IP
查询余额
查询资源地区
均匀提取
API接口介绍
提取IP
查询余额
查询资源地区
通道提取
API接口介绍
提取IP
查询在用IP
提取并查询资源
查询通道数
查询资源地区
隧道代理
产品介绍
使用指南
开发者指南
独享代理
产品介绍
地区锁功能
使用指南
使用指南
开发者指南
API接口
独享代理
API接口介绍
提取IP
查询在用IP
释放IP
替换IP
查询通道数
查询资源地区
独享代理(地区锁)
API接口介绍
提取IP
查询在用IP
释放IP
替换IP
查询资源地区
长效代理
产品介绍
使用指南
使用指南
开发者指南
API接口
API接口介绍
提取IP
查询在用IP
释放IP
查询通道数
查询资源地区
短效代理(全球HTTP)
产品介绍
提取方式
通道提取
按量提取
资源池
超级池
住宅池
使用指南
使用指南
开发者指南
API接口
按量提取
API接口介绍
提取IP
查询在用IP
查询余额
查询国家
通道提取
API接口介绍
提取IP
查询在用IP
查询通道数
查询国家
隧道代理(全球HTTP)
产品介绍
资源池
超级池
住宅池
使用指南
开发者指南
长效代理(全球HTTP)
产品介绍
使用指南
使用指南
开发者指南
API接口
API接口介绍
提取IP资源
查询在用IP资源
查询通道数
独享代理(全球HTTP)
产品介绍
使用指南
使用指南
开发者指南
API接口
API接口介绍
提取资源接口
查询在用资源
查询通道
更换IP
释放资源
产品介绍
>
短效代理
>
使用指南
>
Node语言代码示例
Node语言代码示例
发布时间:2022-06-21 09:24
## nodejs http ```javascript const http = require("http"); const url = require("url"); const targetURL = url.parse("https://test.ipw.cn"); // 如果上面目标站不可用,请使用ip.sb、ipinfo.io、ip-api.com、64.ipcheck.ing const proxyIp = "您的代理IP"; const proxyPort = 端口号; const authKey = "请改成您的Key"; const password = "请改成您的AuthPwd"; const base64 = new Buffer.from(authKey + ":" + password).toString("base64"); const options = { host: proxyIp, port: proxyPort, path: targetURL, method: "GET", headers: { "Host": urlParsed.hostname, "Proxy-Authorization": "Basic " + base64 } }; http.request(options, function (resp) { console.log("response status code: " + resp.statusCode); resp.pipe(process.stdout); }).on("error", function (err) { console.log("request failed: " + err); }).end(); ``` ## nodejs request ```javascript const request = require("https://test.ipw.cn"); // 如果上面目标站不可用,请使用ip.sb、ipinfo.io、ip-api.com、64.ipcheck.ing const targetUrl = "https://api.ipify.org"; const proxyIp = "您的代理IP"; const proxyPort = 端口号; const authKey = "请改成您的Key"; const password = "请改成您的AuthPwd"; const proxyUrl = "http://" + authKey + ":" + password + "@" + proxyIp + ":" + proxyPort; const req = request.defaults({'proxy': proxyUrl}); const options = { url: targetUrl, headers: {} }; req.get(options, function (err, resp, body) { if (err) { return console.log(err); } console.log("response status code: " + resp.statusCode); console.log("response body: " + body); }).on("error", function (err) { console.log("request failed: " + err); }); ``` ## nodejs superagent ```javascript const request = require("superagent"); require("superagent-proxy")(request); const targetUrl = "https://test.ipw.cn"; // 如果上面目标站不可用,请使用ip.sb、ipinfo.io、ip-api.com、64.ipcheck.ing const proxyIp = "您的代理IP"; const proxyPort = 端口号; const authKey = "请改成您的Key"; const password = "请改成您的AuthPwd"; const proxyUrl = "http://" + authKey + ":" + password + "@" + proxyIp + ":" + proxyPort; request.get(targetUrl).proxy(proxyUrl).end(function onResponse(err, resp) { if (err) { return console.log(err); } console.log("response status code: " + resp.statusCode); console.log("response body: " + resp.text); }); ``` ## nodejs axios ```javascript const axios = require("axios") const {HttpsProxyAgent} = require("https-proxy-agent") const targetUrl = "https://test.ipw.cn" // 如果上面目标站不可用,请使用ip.sb、ipinfo.io、ip-api.com、64.ipcheck.ing const proxyIp = "您的代理IP" const proxyPort = 端口号 const authKey = "请改成您的Key" const password = "请改成您的AuthPwd" const proxy = new HttpsProxyAgent(`http://${authKey}:${password}@${proxyIp}:${proxyPort}`) axios.get(targetUrl, { httpAgent: proxy, httpsAgent: proxy, }).then(function (response) { console.log("response body: " + response.data) }).catch(function (error) { console.log("request failed: " + error) }).finally(function () { console.log("request finished.") }) // 如果目标站是HTTPS,则需要使用下面的代码进行代理请求 let httpsProxyAgent = require('https-proxy-agent'); var agent = new HttpsProxyAgent(`http://${authKey}:${password}@${proxyIp}:${proxyPort}`); var config = { url: "https://api.ipify.org", httpsAgent: agent } axios.request(config) .then(function(response) { console.log("response body: " + response.data) }).catch(function(error) { console.log("request failed: " + error) }) ```
上一篇:没有了
下一篇:没有了
相关文章
测试代理的可用性
常见产品问题
IP如何申请和释放
Microsoft edge浏览器使用插件连接代理ip
PHP语言代码示例
怎么查看已申请的IP
本文导读