> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/cn/proxies/datacenter-proxies/select-country.md).

# 选择国家/地区

了解如何定位特定代理位置以及如何使用轮换逻辑。

如果你想访问来自特定位置的 IP，你必须提供一个 `country` – 参数，在用户名中使用两位国家代码。以下是 `country` 参数列表。例如，如果你想使用美国的 country 参数，请添加 `country-US`.

请在下表中查看支持国家的完整列表。

<details>

<summary><strong>Datacenter per IP 支持的国家列表</strong></summary>

<table><thead><tr><th>国家</th><th>国家代码</th><th data-hidden></th></tr></thead><tbody><tr><td>阿根廷</td><td><code>country-AR</code></td><td></td></tr><tr><td>澳大利亚</td><td><code>country-AU</code></td><td></td></tr><tr><td>奥地利</td><td><code>country-AT</code></td><td></td></tr><tr><td>比利时</td><td><code>country-BE</code></td><td></td></tr><tr><td>巴西</td><td><code>country-BR</code></td><td></td></tr><tr><td>加拿大</td><td><code>country-CA</code></td><td></td></tr><tr><td>智利</td><td><code>country-CL</code></td><td></td></tr><tr><td>中国</td><td><code>country-CN</code></td><td></td></tr><tr><td>哥伦比亚</td><td><code>country-CO</code></td><td></td></tr><tr><td>克罗地亚</td><td><code>country-HR</code></td><td></td></tr><tr><td>捷克共和国</td><td><code>country-CZ</code></td><td></td></tr><tr><td>丹麦</td><td><code>country-DK</code></td><td></td></tr><tr><td>芬兰</td><td><code>country-FI</code></td><td></td></tr><tr><td>法国</td><td><code>country-FR</code></td><td></td></tr><tr><td>德国</td><td><code>country-DE</code></td><td></td></tr><tr><td>印度</td><td><code>country-IN</code></td><td></td></tr><tr><td>印度尼西亚</td><td><code>country-ID</code></td><td></td></tr><tr><td>爱尔兰</td><td><code>country-IE</code></td><td></td></tr><tr><td>以色列</td><td><code>country-IL</code></td><td></td></tr><tr><td>意大利</td><td><code>country-IT</code></td><td></td></tr><tr><td>日本</td><td><code>country-JP</code></td><td></td></tr><tr><td>墨西哥</td><td><code>country-MX</code></td><td></td></tr><tr><td>荷兰</td><td><code>country-NL</code></td><td></td></tr><tr><td>秘鲁</td><td><code>country-PE</code></td><td></td></tr><tr><td>菲律宾</td><td><code>country-PH</code></td><td></td></tr><tr><td>波兰</td><td><code>country-PL</code></td><td></td></tr><tr><td>葡萄牙</td><td><code>country-PT</code></td><td></td></tr><tr><td>罗马尼亚</td><td><code>country-RO</code></td><td></td></tr><tr><td>沙特阿拉伯</td><td><code>country-SA</code></td><td></td></tr><tr><td>新加坡</td><td><code>country-SG</code></td><td></td></tr><tr><td>斯洛伐克</td><td><code>country-SK</code></td><td></td></tr><tr><td>西班牙</td><td><code>country-ES</code></td><td></td></tr><tr><td>瑞士</td><td><code>country-CH</code></td><td></td></tr><tr><td>泰国</td><td><code>country-TH</code></td><td></td></tr><tr><td>阿拉伯联合酋长国</td><td><code>country-AE</code></td><td></td></tr><tr><td>英国</td><td><code>country-GB</code></td><td></td></tr><tr><td>美国</td><td><code>country-US</code></td><td></td></tr></tbody></table>

</details>

<details>

<summary><strong>Datacenter per traffic 支持的国家列表</strong></summary>

<table><thead><tr><th>国家</th><th>国家代码</th><th data-hidden></th></tr></thead><tbody><tr><td>阿根廷</td><td><code>country-AR</code></td><td></td></tr><tr><td>澳大利亚</td><td><code>country-AU</code></td><td></td></tr><tr><td>奥地利</td><td><code>country-AT</code></td><td></td></tr><tr><td>比利时</td><td><code>country-BE</code></td><td></td></tr><tr><td>巴西</td><td><code>country-BR</code></td><td></td></tr><tr><td>加拿大</td><td><code>country-CA</code></td><td></td></tr><tr><td>智利</td><td><code>country-CL</code></td><td></td></tr><tr><td>中国</td><td><code>country-CN</code></td><td></td></tr><tr><td>哥伦比亚</td><td><code>country-CO</code></td><td></td></tr><tr><td>克罗地亚</td><td><code>country-HR</code></td><td></td></tr><tr><td>丹麦</td><td><code>country-DK</code></td><td></td></tr><tr><td>爱沙尼亚</td><td><code>country-EE</code></td><td></td></tr><tr><td>芬兰</td><td><code>country-FI</code></td><td></td></tr><tr><td>法国</td><td><code>country-FR</code></td><td></td></tr><tr><td>德国</td><td><code>country-DE</code></td><td></td></tr><tr><td>希腊</td><td><code>country-GR</code></td><td></td></tr><tr><td>匈牙利</td><td><code>country-HU</code></td><td></td></tr><tr><td>印度</td><td><code>country-IN</code></td><td></td></tr><tr><td>印度尼西亚</td><td><code>country-ID</code></td><td></td></tr><tr><td>爱尔兰</td><td><code>country-IE</code></td><td></td></tr><tr><td>以色列</td><td><code>country-IL</code></td><td></td></tr><tr><td>意大利</td><td><code>country-IT</code></td><td></td></tr><tr><td>日本</td><td><code>country-JP</code></td><td></td></tr><tr><td>拉脱维亚</td><td><code>country-LV</code></td><td></td></tr><tr><td>立陶宛</td><td><code>country-LT</code></td><td></td></tr><tr><td>墨西哥</td><td><code>country-MX</code></td><td></td></tr><tr><td>荷兰</td><td><code>country-NL</code></td><td></td></tr><tr><td>新西兰</td><td><code>country-NZ</code></td><td></td></tr><tr><td>挪威</td><td><code>country-NO</code></td><td></td></tr><tr><td>秘鲁</td><td><code>country-PE</code></td><td></td></tr><tr><td>波兰</td><td><code>country-PL</code></td><td></td></tr><tr><td>葡萄牙</td><td><code>country-PT</code></td><td></td></tr><tr><td>罗马尼亚</td><td><code>country-RO</code></td><td></td></tr><tr><td>沙特阿拉伯</td><td><code>country-SA</code></td><td></td></tr><tr><td>新加坡</td><td><code>country-SG</code></td><td></td></tr><tr><td>斯洛伐克</td><td><code>country-SK</code></td><td></td></tr><tr><td>斯洛文尼亚</td><td><code>country-SI</code></td><td></td></tr><tr><td>韩国</td><td><code>country-KR</code></td><td></td></tr><tr><td>西班牙</td><td><code>country-ES</code></td><td></td></tr><tr><td>瑞典</td><td><code>country-SE</code></td><td></td></tr><tr><td>瑞士</td><td><code>country-CH</code></td><td></td></tr><tr><td>泰国</td><td><code>country-TH</code></td><td></td></tr><tr><td>英国</td><td><code>country-GB</code></td><td></td></tr><tr><td>美国</td><td><code>country-US</code></td><td></td></tr></tbody></table>

</details>

例如，如果你只想轮换美国代理池，请使用轮换端口 `8000` 并配合一个参数 `country-US` 放在你的用户名中：

```bash
curl -x dc.oxylabs.io:8000 -U 'user-USERNAME-country-US:PASSWORD' https://ip.oxylabs.io/location
```

**代码示例**

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

```sh
curl -x dc.oxylabs.io:8000 -U 'user-USERNAME-country-COUNTRY:PASSWORD' https://ip.oxylabs.io/location
```

{% endtab %}

{% tab title="Python" %}

<pre class="language-python"><code class="lang-python">#pip install requests
<strong>import requests
</strong>
用户名 = 'USERNAME'
password = 'PASSWORD'
country = 'COUNTRY'
proxy = 'dc.oxylabs.io:8000'

代理 = {
   "https": ('https://user-%s-country-%s:%s@%s' % (username, country, password, proxy))
}

response=requests.get("https://ip.oxylabs.io/location", proxies=proxies)

print(response.content)
</code></pre>

{% endtab %}

{% tab title="Node.js" %}

```javascript
//npm install axios
const axios = require("axios");
const https = require("https");

const client = axios.create({
    httpsAgent: new https.Agent({
        rejectUnauthorized: false,
    }),
});
const username = 'USERNAME';
const country = 'COUNTRY'
const password = 'PASSWORD'

客户端
    .get("https://ip.oxylabs.io/location", {
        proxy: {
            protocol: "https",
            host: "dc.oxylabs.io",
            port: 8000,
            auth: {
                username: `user-${username}-country-${country}`,
                password: password,
            },
        },
    })
    .then((res) => {
        console.log(res.data);
    })
    .catch((err) => console.error(err));

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$username = 'USERNAME';
$country = 'COUNTRY';
$password = 'PASSWORD';
$proxy = 'dc.oxylabs.io:8000';
$target = 'https://ip.oxylabs.io/location';

$request = curl_init($target);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_PROXY, $proxy);
curl_setopt($request, CURLOPT_PROXYUSERPWD, "user-$username-country-$country:$password");
$responseBody = curl_exec($request);
$error = curl_error($request);
curl_close($request);

if ($responseBody !== false) {
    echo 'Response: ' . $responseBody;
} else {
    echo 'Failed to connect to proxy: ' . $error;
}

```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"fmt"
	"io"
	"net/http"
	"net/url"
)

func main() {
	username, country, password, entry := "USERNAME", "COUNTRY", "PASSWORD", "dc.oxylabs.io:8000"

	proxy, err := url.Parse(fmt.Sprintf("https://user-%s-country-%s:%s@%s", username, country, password, entry))
	if err != nil {
		panic(err)
	}

	transport := &http.Transport{
		Proxy: http.ProxyURL(proxy),
	}
	client := &http.Client{Transport: transport}
	target := "https://ip.oxylabs.io/location"
	response, err := client.Get(target)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	body, err := io.ReadAll(response.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println("响应：")
	fmt.Println(string(body))
}

```

{% endtab %}

{% tab title="Java" %}

```java
package com.example;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Base64;

import org.apache.hc.client5.http.fluent.Request;
import org.apache.hc.core5.http.HttpHost;

public class App {
    public static void main(String[] args) throws IOException, URISyntaxException {
        String targetUrl = "http://ip.oxylabs.io/location";
        String username = "USERNAME";
        String country = "COUNTRY";
        String password = "PASSWORD";
        String proxy = "dc.oxylabs.io:8000";

        URI proxyURI = new URI(String.format("https://user-%s-country-%s:%s@%s", username, country, password, proxy));

        String basicAuth = new String(
                Base64.getEncoder()
                        .encode(
                                proxyURI.getUserInfo().getBytes()));
        String response = Request.get(targetUrl)
                .addHeader("Proxy-Authorization", "Basic " + basicAuth)
                .viaProxy(HttpHost.create(proxyURI))
                .execute().returnContent().asString();

        System.out.println(response);
    }
}

```

{% endtab %}

{% tab title="C#" %}

```csharp
using System.Net;

// .NET 当前不支持 HTTPS 代理
var proxy = new WebProxy {
    Address = new Uri("dc.oxylabs.io:8000"),
    Credentials = new NetworkCredential(
        userName: "user-USERNAME-country-COUNTRY",
        password: "PASSWORD"
    )
};

var httpClientHandler = new HttpClientHandler {Proxy = proxy};

using var client = new HttpClient(handler: httpClientHandler, disposeHandler: true);

var result = await client.GetStringAsync("https://ip.oxylabs.io/location");
Console.WriteLine(result);
```

{% endtab %}
{% endtabs %}

#### 不同订阅方式之间的差异

`Datacenter per IP` 提供轮换端口和 `country` 该参数将获得一个 **来自其代理列表中所选国家的随机 IP** ，每次新请求都会更换。\
\
`Datacenter per traffic` 提供轮换端口和 `country` 该参数将获得 **来自整个代理池中所选国家的随机 IP。**

{% hint style="info" %}
我们使用 [**MaxMind GeoIP2**](https://www.maxmind.com/en/geoip2-databases) 数据库，用于确定 IP 位置。
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.oxylabs.io/products/cn/proxies/datacenter-proxies/select-country.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
