使用代理轮换工具的会话控制
使用代理轮换工具可以保持相同的 IP 地址。您首先要知道您的代理拥有多少代理轮换工具。然后将 --proxy-header "Proxy-Server: sXXX"
标头添加到您的请求中,其中 sXXX
是代理的编号,例如 s5
或 s2541
。
代码示例
user1@machine:~$ curl -x vm.oxylabs.io:60000 -U user1:pass1 https://ip.oxylabs.io/location --proxy-header "Proxy-Server: s10"
1.2.30.40
user1@machine:~$ curl -x vm.oxylabs.io:60000 -U user1:pass1 https://ip.oxylabs.io/location --proxy-header "Proxy-Server: s10"
1.2.30.40
user1@machine:~$ curl -x vm.oxylabs.io:60000 -U user1:pass1 https://ip.oxylabs.io/location --proxy-header "Proxy-Server: s10"
1.2.30.40
<?php
$query = curl_init('https://ip.oxylabs.io/location');
curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_PROXY, 'http://vm.oxylabs.io:60000');
curl_setopt($query, CURLOPT_PROXYUSERPWD, "username:password");
curl_setopt($query, CURLOPT_PROXYHEADER, [
"Proxy-Server: s10",
]);
$output = curl_exec($query);
curl_close($query);
if ($output) {
echo $output;
}
import requests
class ProxyAdapter(requests.adapters.HTTPAdapter):
def proxy_headers(self, proxy):
headers = super(ProxyAdapter, self).proxy_headers(proxy)
headers['Proxy-Server'] = 's10'
return headers
s = requests.Session()
s.proxies = {'http': 'http://username:password@vm.oxylabs.io:60000',
'https': 'http://username:password@vm.oxylabs.io:60000'}
s.mount('http://', ProxyAdapter())
s.mount('https://', ProxyAdapter())
response = s.get('https://ip.oxylabs.io/location')
print(response.text)
using System;
using System.Net;
class Example
{
static void Main()
{
var client = new WebClient();
client.Proxy = new WebProxy("http://vm.oxylabs.io:60000");
client.Proxy.Credentials = new NetworkCredential("user1", "pass1");
client.Headers.Add("Proxy-Server", "s10");
Console.WriteLine(client.DownloadString("https://ip.oxylabs.io/location"));
}
}
Last updated