以下示例展示如何在各种编程环境中配置和使用代理
host:port:username:password 格式的代理地址username:password@host:port
# 使用动态住宅代理访问目标网站
curl -x username:password@proxy-host:3128 https://httpbin.org/ip
# 指定国家/城市(如果套餐支持)
curl -x username-country-us:password@proxy-host:3128 https://httpbin.org/ip
import requests
proxy = "http://username:password@proxy-host:3128"
proxies = {"http": proxy, "https": proxy}
response = requests.get("https://httpbin.org/ip", proxies=proxies)
print(response.json())
// 使用 https-proxy-agent
const { HttpsProxyAgent } = require('https-proxy-agent');
const fetch = require('node-fetch');
const agent = new HttpsProxyAgent('http://username:password@proxy-host:3128');
const response = await fetch('https://httpbin.org/ip', { agent });
console.log(await response.json());
$proxy = 'username:password@proxy-host:3128';
$ch = curl_init('https://httpbin.org/ip');
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);
curl_close($ch);
import (
"net/http"
"net/url"
)
proxyURL, _ := url.Parse("http://username:password@proxy-host:3128")
client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
}
resp, _ := client.Get("https://httpbin.org/ip")
推荐使用 SwitchyOmega(Chrome)或 FoxyProxy(Firefox),配置 HTTP 代理地址为 proxy-host:3128,填入用户名密码即可。