# 代理轮换器 - 可选

此服务为可选；如果您希望使用 Proxy Rotator，请联系您的客户经理以获取域名。

我们为您分配的代理列表提供了一个单一端点，无需连接到单个 IP。每次请求时，端点会获取不同的 IP。请参见下面的示例以了解如何将该端点用作代理。

{% hint style="info" %}
该 [vm.oxylabs.io](http://vm.oxylabs.io) 域仅为示例。请联系您的客户经理以获取转发给您的域名。
{% endhint %}

{% hint style="success" %}
Proxy Rotator 应仅与端口一起使用 `60000`.
{% endhint %}

#### 代码示例

{% tabs %}
{% tab title="cURL" %}

```shell
curl -x vm.oxylabs.io:60000 -U user1:pass1 https://ip.oxylabs.io/location
```

{% endtab %}

{% tab title="PHP" %}

```php
<?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");
$output = curl_exec($query);
curl_close($query);
if ($output) {
    echo $output;
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

response = requests.get(
    'https://ip.oxylabs.io/location',
    proxies={'http': 'http://user1:pass1@vm.oxylabs.io:60000',
            'https': 'http://user1:pass1@vm.oxylabs.io:60000'}
)
print(response.text)
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net;

class Example
{
    static void Main()
    {
        var proxy = new WebProxy
        {
            Address = new Uri($"http://vm.oxylabs.io:60000"),
            BypassProxyOnLocal = false,
            UseDefaultCredentials = false,
            Credentials = new NetworkCredential("username", "password")
        };

        var handler = new HttpClientHandler
        {
            Proxy = proxy,
        };

        HttpClient client = new HttpClient(handler);
        var task = Task.Run(async () =>
        {
            var response = await client.GetAsync("https://ip.oxylabs.io/location");
            var content = response.Content;
            var result = await content.ReadAsStringAsync();
            return result;
        });

        task.Wait();
        Console.WriteLine(task.Result);
    }
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
代理轮换仅从您在初始设置时选择的 ASN 所在的代理中选择 IP。自动轮换不会切换到不同的 ISP，也不会更改您未选择的 ASN。
{% endhint %}

### 使用 Proxy Rotator 的会话控制

可以使用 Proxy Rotator 保持相同的 IP 地址。首先，您需要知道您的 Proxy Rotator 有多少个代理。然后将 `--proxy-header "Proxy-Server: sXXX"` 头添加到您的请求中，其中 `sXXX` 是代理的编号，例如， `s5` 或 `s2541`.

#### 代码示例

{% tabs %}
{% tab title="cURL" %}

```shell
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
```

{% endtab %}

{% tab title="PHP" %}

```php
<?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;
}
```

{% endtab %}

{% tab title="Python" %}

```python
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)
```

{% endtab %}

{% tab title="C#" %}

```csharp
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"));
    }
}
```

{% endtab %}
{% endtabs %}
