> 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/residential-proxies/location-settings.md).

# 位置设置

进一步了解住宅代理的位置设置。这里提供从大洲、特定城市到坐标或地理哈希的位置定位指南。

Oxylabs 住宅代理覆盖全球 195 多个地点，可将流量精细路由到 **country**, **city**, **state**, **洲**, **ZIP 代码**, **地理哈希**, **ASN**，或 **坐标** 级别。位置参数会直接添加到您的代理 `用户名` 字符串，或通过自定义标头传递。

{% hint style="info" %}
**位置映射：** 我们使用 [**MaxMind GeoIP2**](https://www.maxmind.com/en/geoip2-databases) 用于分配我们的出口节点的数据库 `cc`, `st`，以及 `city` 数值。此数据库每周更新。

其他一些公共 IP 数据库可能会显示不同的位置。在不应该出现任何位置不匹配的情况下，请再次核对分配的代理在目标网站所使用的 IP 数据库中的位置是否相同。
{% endhint %}

<table><thead><tr><th width="105">定位</th><th width="194">参数</th><th>说明</th></tr></thead><tbody><tr><td><a href="#country"><strong>国家</strong></a></td><td><code>cc</code></td><td>ISO 3166-1 alpha-2 代码。支持按国家的入口端口。<br>例如： <code>customer-USERNAME-cc-US</code></td></tr><tr><td><a href="#city"><strong>城市</strong></a></td><td><code>city</code></td><td>英文城市名。需要 <code>cc</code> 参数以获得最高精度。<br>例如： <code>customer-USERNAME-cc-US-city-new_york</code></td></tr><tr><td><a href="#state"><strong>州</strong></a></td><td><code>st</code></td><td>仅限美国州。需要 <code>us_</code> 前缀。<br>例如： <code>customer-USERNAME-st-us_california</code></td></tr><tr><td><a href="#continent"><strong>洲</strong></a></td><td><code>cn</code></td><td>两字母洲代码（<code>AF</code>, <code>AN</code>, <code>AS</code>, <code>EU</code>, <code>NA</code>, <code>OC</code>, <code>SA</code>）。<br>例如： <code>customer-USERNAME-cn-EU</code></td></tr><tr><td><a href="#zip-postal-code"><strong>ZIP / 邮政编码</strong></a></td><td><code>postalcode</code></td><td>仅限 5 位美国 ZIP 代码。需要 <code>cc-US</code>.<br>例如： <code>customer-USERNAME-cc-US-postalcode-90210</code></td></tr><tr><td><a href="#geo-hash"><strong>地理哈希</strong></a></td><td><code>地理哈希</code></td><td>网格单元级别 1 到 4（<code>9</code> to <code>drq4</code>）。与其他地理参数互斥。<br>例如： <code>customer-USERNAME-geohash-u09</code></td></tr><tr><td><a href="#asn-targeting"><strong>ASN 定位</strong></a></td><td><code>ASN</code></td><td>定位到特定的自治系统编号。如果 <code>cc</code> 存在，则会被覆盖。<br>例如： <code>customer-USERNAME-ASN-21928</code></td></tr><tr><td><a href="#coordinates"><strong>坐标</strong></a></td><td><code>X-Oxylabs-Geolocation</code></td><td>作为 HTTP 代理头传递。最小半径 10 英里。<br>例如： <code>纬度:经度;半径</code></td></tr></tbody></table>

{% hint style="warning" %}
**对于来自中国大陆的请求**，请参见专用的 HTTPS 区域 [中国入口节点](#china-entry-nodes).
{% endhint %}

***

## 国家

添加 `cc` 参数到授权头中，可使用 2 位 ISO [**3166-1 alpha-2 格式**](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) 国家代码（例如， `DE` 表示德国， `GB` 表示英国， `JP` 表示日本）：

```
customer-USERNAME-cc-DE:PASSWORD
```

#### 代码示例

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

```shell
curl -x pr.oxylabs.io:7777 -U "customer-USERNAME-cc-DE:PASSWORD" https://ip.oxylabs.io/location
```

{% endtab %}

{% tab title="Python" %}

```python
import urllib.request

用户名 = 'USERNAME'
password = 'PASSWORD'
country = 'DE'
entry = f'http://customer-{username}-cc-{country}:{password}@pr.oxylabs.io:7777'

query = urllib.request.ProxyHandler({'http': entry, 'https': entry})
execute = urllib.request.build_opener(query)
print(execute.open('https://ip.oxylabs.io/location').read().decode('utf-8'))
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$username = 'USERNAME';
$password = 'PASSWORD';
$country = 'DE';
$proxy = 'pr.oxylabs.io:7777';
$query = curl_init('https://ip.oxylabs.io/location');
curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_PROXY, "http://$proxy");
curl_setopt($query, CURLOPT_PROXYUSERPWD, "customer-$username-cc-$country:$password");
$output = curl_exec($query);
curl_close($query);
if ($output)
    echo $output;
?>
```

{% endtab %}

{% tab title="Java" %}

```java
package example;

import org.apache.http.HttpHost;
import org.apache.http.client.fluent.*;

public class Example {
    public static void main(String[] args) throws Exception {
        HttpHost entry = new HttpHost("pr.oxylabs.io", 7777);
        String query = Executor.newInstance()
            .auth(entry, "customer-USERNAME-cc-DE", "PASS")
            .execute(Request.Get("http://ip.oxylabs.io/location").viaProxy(entry))
            .returnContent().asString();
        System.out.println(query);
    }
}
```

{% endtab %}

{% tab title="C#" %}

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

class Example
{
    static void Main()
    {
        var client = new WebClient();
        client.Proxy = new WebProxy("pr.oxylabs.io:7777");
        client.Proxy.Credentials = new NetworkCredential("customer-USERNAME-cc-DE", "PASSWORD");
        Console.WriteLine(client.DownloadString("https://ip.oxylabs.io/location"));
    }
}
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'uri'
require 'net/http'

uri = URI.parse('https://ip.oxylabs.io/location')
proxy = Net::HTTP::Proxy('pr.oxylabs.io', 7777, 'customer-USERNAME-cc-DE', 'PASSWORD')

req = Net::HTTP::Get.new(uri.path)

result = proxy.start(uri.host,uri.port) do |http|
    http.request(req)
end

puts result.body
```

{% endtab %}
{% endtabs %}

### 按国家的入口节点

或者，直接连接到按国家的域入口点，而无需修改您的用户名参数。以下对 `ip.oxylabs.io/location` 的示例请求来自一个随机土耳其 IP：

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

```shell
curl -x tr-pr.oxylabs.io:30000 -U "customer-USERNAME:PASSWORD" https://ip.oxylabs.io/location
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$username = 'USERNAME';
$password = 'PASSWORD';
$proxy = 'tr-pr.oxylabs.io:30000';
$query = curl_init('https://ip.oxylabs.io/location');
curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_PROXY, "http://$proxy");
curl_setopt($query, CURLOPT_PROXYUSERPWD, "customer-$username:$password");
$output = curl_exec($query);
curl_close($query);
if ($output)
    echo $output;
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import urllib.request
import random
用户名 = 'USERNAME'
password = 'PASSWORD'
entry = ('http://customer-%s:%s@tr-pr.oxylabs.io:30000' %
    (username, password))
query = urllib.request.ProxyHandler({
    'http': entry,
    'https': entry,
})
execute = urllib.request.build_opener(query)
print(execute.open('https://ip.oxylabs.io/location').read())
```

{% endtab %}

{% tab title="Java" %}

```java
package example;

import org.apache.http.HttpHost;
import org.apache.http.client.fluent.*;

public class Example {
    public static void main(String[] args) throws Exception {
        HttpHost entry = new HttpHost("tr-pr.oxylabs.io", 30000);
        String query = Executor.newInstance()
            .auth(entry, "customer-USERNAME", "PASS")
            .execute(Request.Get("http://ip.oxylabs.io/location").viaProxy(entry))
            .returnContent().asString();
        System.out.println(query);
    }
}
```

{% endtab %}

{% tab title="C#" %}

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

class Example
{
    static void Main()
    {
        var client = new WebClient();
        client.Proxy = new WebProxy("tr-pr.oxylabs.io:30000");
        client.Proxy.Credentials = new NetworkCredential("customer-USERNAME", "PASSWORD");
        Console.WriteLine(client.DownloadString("https://ip.oxylabs.io/location"));
    }
}
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
#!/usr/bin/ruby

require 'uri'
require 'net/http'

uri = URI.parse('https://ip.oxylabs.io/location')
proxy = Net::HTTP::Proxy('tr-pr.oxylabs.io', 30000, 'customer-USERNAME', 'PASSWORD')

req = Net::HTTP::Get.new(uri.path)

result = proxy.start(uri.host,uri.port) do |http|
    http.request(req)
end

puts result.body
```

{% endtab %}
{% endtabs %}

请参见仪表板获取入口点信息。下载完整的随机入口点列表，或在下表中查找。

{% file src="/files/7c7d1740cd8a470db87f322819c51b4c570c2d10" %}

<details>

<summary><strong>可用入口节点表</strong></summary>

| <p><strong>随机</strong><br>pr.oxylabs.io:7777</p>          | <p><strong>美国</strong><br>us-pr.oxylabs.io:10000</p>         | <p><strong>加拿大</strong><br>ca-pr.oxylabs.io:30000</p>         |
| --------------------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------- |
| <p><strong>英国</strong><br>gb-pr.oxylabs.io:20000</p>      | <p><strong>德国</strong><br>de-pr.oxylabs.io:30000</p>         | <p><strong>法国</strong><br>fr-pr.oxylabs.io:40000</p>          |
| <p><strong>西班牙</strong><br>es-pr.oxylabs.io:10000</p>     | <p><strong>意大利</strong><br>it-pr.oxylabs.io:20000</p>        | <p><strong>瑞典</strong><br>se-pr.oxylabs.io:30000</p>          |
| <p><strong>希腊</strong><br>gr-pr.oxylabs.io:40000</p>      | <p><strong>葡萄牙</strong><br>pt-pr.oxylabs.io:10000</p>        | <p><strong>荷兰</strong><br>nl-pr.oxylabs.io:20000</p>          |
| <p><strong>比利时</strong><br>be-pr.oxylabs.io:30000</p>     | <p><strong>印度尼西亚</strong><br>id-pr.oxylabs.io:10000</p>      | <p><strong>乌克兰（未被占领地区）</strong><br>ua-pr.oxylabs.io:10000</p> |
| <p><strong>波兰</strong><br>pl-pr.oxylabs.io:20000</p>      | <p><strong>以色列</strong><br>il-pr.oxylabs.io:20000</p>        | <p><strong>土耳其</strong><br>tr-pr.oxylabs.io:30000</p>         |
| <p><strong>澳大利亚</strong><br>au-pr.oxylabs.io:40000</p>    | <p><strong>马来西亚</strong><br>my-pr.oxylabs.io:10000</p>       | <p><strong>泰国</strong><br>th-pr.oxylabs.io:20000</p>          |
| <p><strong>韩国</strong><br>kr-pr.oxylabs.io:30000</p>      | <p><strong>日本</strong><br>jp-pr.oxylabs.io:40000</p>         | <p><strong>菲律宾</strong><br>ph-pr.oxylabs.io:10000</p>         |
| <p><strong>新加坡</strong><br>sg-pr.oxylabs.io:20000</p>     | <p><strong>中国</strong><br>cn-pr.oxylabs.io:30000</p>         | <p><strong>香港</strong><br>hk-pr.oxylabs.io:40000</p>          |
| <p><strong>台湾</strong><br>tw-pr.oxylabs.io:10000</p>      | <p><strong>印度</strong><br>in-pr.oxylabs.io:20000</p>         | <p><strong>巴基斯坦</strong><br>pk-pr.oxylabs.io:30000</p>        |
| <p><strong>哈萨克斯坦</strong><br>kz-pr.oxylabs.io:30000</p>   | <p><strong>阿联酋</strong><br>ae-pr.oxylabs.io:40000</p>        | <p><strong>墨西哥</strong><br>mx-pr.oxylabs.io:10000</p>         |
| <p><strong>巴西</strong><br>br-pr.oxylabs.io:20000</p>      | <p><strong>阿根廷</strong><br>ar-pr.oxylabs.io:30000</p>        | <p><strong>智利</strong><br>cl-pr.oxylabs.io:40000</p>          |
| <p><strong>秘鲁</strong><br>pe-pr.oxylabs.io:10000</p>      | <p><strong>厄瓜多尔</strong><br>ec-pr.oxylabs.io:20000</p>       | <p><strong>哥伦比亚</strong><br>co-pr.oxylabs.io:30000</p>        |
| <p>​​<strong>南非</strong><br>za-pr.oxylabs.io:40000</p>    | <p><strong>埃及</strong><br>eg-pr.oxylabs.io:10000</p>         | <p><strong>安哥拉</strong><br>ao-pr.oxylabs.io:40000</p>         |
| <p><strong>喀麦隆</strong><br>cm-pr.oxylabs.io:41000</p>     | <p><strong>中非共和国</strong><br>cf-pr.oxylabs.io:42000</p>      | <p><strong>乍得</strong><br>td-pr.oxylabs.io:43000</p>          |
| <p><strong>贝宁</strong><br>bj-pr.oxylabs.io:44000</p>      | <p><strong>埃塞俄比亚</strong><br>et-pr.oxylabs.io:45000</p>      | <p><strong>吉布提</strong><br>dj-pr.oxylabs.io:46000</p>         |
| <p><strong>冈比亚</strong><br>gm-pr.oxylabs.io:47000</p>     | <p><strong>加纳</strong><br>gh-pr.oxylabs.io:48000</p>         | <p><strong>科特迪瓦</strong><br>ci-pr.oxylabs.io:49000</p>        |
| <p><strong>肯尼亚</strong><br>ke-pr.oxylabs.io:10000</p>     | <p><strong>利比里亚</strong><br>lr-pr.oxylabs.io:11000</p>       | <p><strong>马达加斯加</strong><br>mg-pr.oxylabs.io:12000</p>       |
| <p><strong>马里</strong><br>ml-pr.oxylabs.io:13000</p>      | <p><strong>毛里塔尼亚</strong><br>mr-pr.oxylabs.io:14000</p>      | <p><strong>毛里求斯</strong><br>mu-pr.oxylabs.io:15000</p>        |
| <p><strong>摩洛哥</strong><br>ma-pr.oxylabs.io:16000</p>     | <p><strong>莫桑比克</strong><br>mz-pr.oxylabs.io:17000</p>       | <p><strong>尼日利亚</strong><br>ng-pr.oxylabs.io:18000</p>        |
| <p><strong>塞内加尔</strong><br>sn-pr.oxylabs.io:19000</p>    | <p><strong>塞舌尔</strong><br>sc-pr.oxylabs.io:20000</p>        | <p><strong>津巴布韦</strong><br>zw-pr.oxylabs.io:21000</p>        |
| <p><strong>南苏丹</strong><br>ss-pr.oxylabs.io:22000</p>     | <p><strong>苏丹</strong><br>sd-pr.oxylabs.io:23000</p>         | <p><strong>多哥</strong><br>tg-pr.oxylabs.io:24000</p>          |
| <p><strong>突尼斯</strong><br>tn-pr.oxylabs.io:25000</p>     | <p><strong>乌干达</strong><br>ug-pr.oxylabs.io:26000</p>        | <p><strong>赞比亚</strong><br>zm-pr.oxylabs.io:27000</p>         |
| <p><strong>阿富汗</strong><br>af-pr.oxylabs.io:28000</p>     | <p><strong>巴林</strong><br>bh-pr.oxylabs.io:29000</p>         | <p><strong>孟加拉国</strong><br>bd-pr.oxylabs.io:30000</p>        |
| <p><strong>亚美尼亚</strong><br>am-pr.oxylabs.io:31000</p>    | <p><strong>不丹</strong><br>bt-pr.oxylabs.io:32000</p>         | <p><strong>缅甸</strong><br>mm\_pr.oxylabs.io:33000</p>         |
| <p><strong>柬埔寨</strong><br>kh-pr.oxylabs.io:34000</p>     | <p><strong>格鲁吉亚</strong><br>ge-pr.oxylabs.io:36000</p>       | <p><strong>伊拉克</strong><br>iq-pr.oxylabs.io:37000</p>         |
| <p><strong>约旦</strong><br>jo-pr.oxylabs.io:38000</p>      | <p><strong>黎巴嫩</strong><br>lb-pr.oxylabs.io:39000</p>        | <p><strong>马尔代夫</strong><br>mv-pr.oxylabs.io:40000</p>        |
| <p><strong>蒙古</strong><br>mn-pr.oxylabs.io:41000</p>      | <p><strong>阿曼</strong><br>om-pr.oxylabs.io:42000</p>         | <p><strong>卡塔尔</strong></p><p>qa-pr.oxylabs.io:43000</p>      |
| <p><strong>沙特阿拉伯</strong><br>sa-pr.oxylabs.io:44000</p>   | <p><strong>越南</strong><br>vn-pr.oxylabs.io:45000</p>         | <p><strong>土库曼斯坦</strong><br>tm-pr.oxylabs.io:46000</p>       |
| <p><strong>乌兹别克斯坦</strong><br>uz-pr.oxylabs.io:47000</p>  | <p><strong>也门</strong><br>ye-pr.oxylabs.io:48000</p>         | <p><strong>阿尔巴尼亚</strong></p><p>al-pr.oxylabs.io:49000</p>    |
| <p><strong>安道尔</strong><br>ad-pr.oxylabs.io:10000</p>     | <p><strong>奥地利</strong><br>at-pr.oxylabs.io:11000</p>        | <p><strong>波黑</strong><br>ba-pr.oxylabs.io:13000</p>          |
| <p><strong>保加利亚</strong><br>bg-pr.oxylabs.io:14000</p>    | <p><strong>阿塞拜疆</strong><br>az-pr.oxylabs.io:20000</p>       | <p><strong>克罗地亚</strong><br>hr-pr.oxylabs.io:16000</p>        |
| <p><strong>塞浦路斯</strong><br>cy-pr.oxylabs.io:35000</p>    | <p><strong>捷克共和国</strong></p><p>cz-pr.oxylabs.io:18000</p>   | <p><strong>丹麦</strong><br>dk-pr.oxylabs.io:19000</p>          |
| <p><strong>爱沙尼亚</strong><br>ee-pr.oxylabs.io:20000</p>    | <p><strong>芬兰</strong><br>fi-pr.oxylabs.io:21000</p>         | <p><strong>匈牙利</strong><br>hu-pr.oxylabs.io:23000</p>         |
| <p><strong>冰岛</strong><br>is-pr.oxylabs.io:24000</p>      | <p><strong>爱尔兰</strong><br>ie-pr.oxylabs.io:25000</p>        | <p><strong>拉脱维亚</strong><br>lv-pr.oxylabs.io:26000</p>        |
| <p><strong>列支敦士登</strong><br>li-pr.oxylabs.io:27000</p>   | <p><strong>立陶宛</strong><br>lt-pr.oxylabs.io:28000</p>        | <p><strong>卢森堡</strong><br>lu-pr.oxylabs.io:29000</p>         |
| <p><strong>马耳他</strong><br>mt-pr.oxylabs.io:30000</p>     | <p><strong>摩纳哥</strong><br>mc-pr.oxylabs.io:31000</p>        | <p><strong>摩尔多瓦</strong><br>md-pr.oxylabs.io:32000</p>        |
| <p><strong>黑山</strong><br>me-pr.oxylabs.io:33000</p>      | <p><strong>挪威</strong><br>no-pr.oxylabs.io:34000</p>         | <p><strong>罗马尼亚</strong><br>ro-pr.oxylabs.io:35000</p>        |
| <p><strong>塞尔维亚</strong><br>rs-pr.oxylabs.io:36000</p>    | <p><strong>斯洛伐克</strong><br>sk-pr.oxylabs.io:37000</p>       | <p><strong>斯洛文尼亚</strong><br>si-pr.oxylabs.io:38000</p>       |
| <p><strong>瑞士</strong><br>ch-pr.oxylabs.io:39000</p>      | <p><strong>马其顿</strong></p><p>mk-pr.oxylabs.io:40000</p>     | <p><strong>巴哈马</strong><br>bs-pr.oxylabs.io:41000</p>         |
| <p><strong>伯利兹</strong><br>bz-pr.oxylabs.io:42000</p>     | <p><strong>英属维尔京群岛</strong><br>vg-pr.oxylabs.io:43000</p>    | <p><strong>哥斯达黎加</strong><br>cr-pr.oxylabs.io:44000</p>       |
| <p><strong>纳米比亚</strong><br>na-pr.oxylabs.io:28000</p>    | <p><strong>多米尼克</strong><br>dm-pr.oxylabs.io:46000</p>       | <p><strong>海地</strong><br>ht-pr.oxylabs.io:47000</p>          |
| <p><strong>洪都拉斯</strong><br>hn-pr.oxylabs.io:48000</p>    | <p><strong>牙买加</strong><br>jm-pr.oxylabs.io:49000</p>        | <p><strong>阿鲁巴</strong><br>aw-pr.oxylabs.io:10000</p>         |
| <p><strong>巴拿马</strong><br>pa-pr.oxylabs.io:11000</p>     | <p><strong>波多黎各</strong><br>pr-pr.oxylabs.io:12000</p>       | <p><strong>特立尼达和多巴哥</strong><br>tt-pr.oxylabs.io:13000</p>    |
| <p><strong>斐济</strong><br>fj-pr.oxylabs.io:14000</p>      | <p><strong>新西兰</strong><br>nz-pr.oxylabs.io:15000</p>        | <p><strong>玻利维亚</strong><br>bo-pr.oxylabs.io:16000</p>        |
| <p><strong>巴拉圭</strong><br>py-pr.oxylabs.io:17000</p>     | <p><strong>乌拉圭</strong><br>uy-pr.oxylabs.io:18000</p>        | <p><strong>委内瑞拉</strong><br>ve-pr.oxylabs.io:19000</p>        |
| <p><strong>欧盟</strong><br>eu-pr.oxylabs.io:10000</p>      | <p><strong>多米尼加共和国</strong></p><p>do-pr.oxylabs.io:21000</p> | <p><strong>老挝</strong></p><p>la-pr.oxylabs.io:22000</p>       |
| <p><strong>坦桑尼亚</strong></p><p>tz-pr.oxylabs.io:23000</p> | <p><strong>斯里兰卡</strong></p><p>lk-pr.oxylabs.io:24000</p>    | <p><strong>文莱</strong></p><p>bn-pr.oxylabs.io:25000</p>       |
| <p><strong>尼泊尔</strong></p><p>np-pr.oxylabs.io:26000</p>  | <p><strong>科威特</strong></p><p>kw-pr.oxylabs.io:20000</p>     | <p><strong>危地马拉</strong></p><p>gt-pr.oxylabs.io:27000</p>     |
| <p><strong>阿尔及利亚</strong><br>dz-pr.oxylabs.io:29000</p>   |                                                              |                                                               |

</details>

***

## 城市

使用以下参数定位特定城市的代理 `city` 参数与匹配的国家代码（`cc`）。多词城市名使用下划线而不是空格（例如， `new_york`, `rio_de_janeiro`).

```
customer-USERNAME-cc-US-city-los_angeles:PASSWORD
```

#### 代码示例

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

```shell
curl -x pr.oxylabs.io:7777 -U "customer-USERNAME-cc-DE-city-munich:PASSWORD" https://ip.oxylabs.io/location
```

{% endtab %}

{% tab title="Python" %}

```python
import urllib.request
import random
用户名 = 'USERNAME'
password = 'PASSWORD'
country = 'DE'
city = 'munich'
entry = ('http://customer-%s-cc-%s-city-%s:%s@pr.oxylabs.io:7777' %
    (username, country, city, password))
query = urllib.request.ProxyHandler({
    'http': entry,
    'https': entry,
})
execute = urllib.request.build_opener(query)
print(execute.open('https://ip.oxylabs.io/location').read())
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$username = 'USERNAME';
$password = 'PASSWORD';
$country = 'DE';
$city = 'munich';
$proxy = 'pr.oxylabs.io:7777';
$query = curl_init('https://ip.oxylabs.io/location');
curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_PROXY, "http://$proxy");
curl_setopt($query, CURLOPT_PROXYUSERPWD, "customer-$username-cc-$country-city-$city:$password");
$output = curl_exec($query);
curl_close($query);
if ($output)
    echo $output;
?>
```

{% endtab %}

{% tab title="Java" %}

```java
package example;

import org.apache.http.HttpHost;
import org.apache.http.client.fluent.*;

public class Example {
    public static void main(String[] args) throws Exception {
        HttpHost entry = new HttpHost("pr.oxylabs.io", 7777);
        String query = Executor.newInstance()
            .auth(entry, "customer-USERNAME-cc-DE-city-munich", "PASS")
            .execute(Request.Get("http://ip.oxylabs.io/location").viaProxy(entry))
            .returnContent().asString();
        System.out.println(query);
    }
}
```

{% endtab %}

{% tab title="C#" %}

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

class Example
{
    static void Main()
    {
        var client = new WebClient();
        client.Proxy = new WebProxy("pr.oxylabs.io:7777");
        client.Proxy.Credentials = new NetworkCredential("customer-USERNAME-cc-DE-city-munich", "PASSWORD");
        Console.WriteLine(client.DownloadString("https://ip.oxylabs.io/location"));
    }
}
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'uri'
require 'net/http'

uri = URI.parse('https://ip.oxylabs.io/location')
proxy = Net::HTTP::Proxy('pr.oxylabs.io', 7777, 'customer-USERNAME-cc-DE-city-munich', 'PASSWORD')

req = Net::HTTP::Get.new(uri.path)

result = proxy.start(uri.host,uri.port) do |http|
    http.request(req)
end

puts result.body
```

{% endtab %}
{% endtabs %}

点击下面的文件下载支持的城市列表：

{% file src="/files/1017765116d8de37fe09b6dd2a9045ddcc38e33c" %}

{% hint style="info" %}
我们支持全球每个城市，但由于 住宅代理 的动态特性，我们不能保证在特定时刻都一定有该处代理。最热门的城市覆盖很好。
{% endhint %}

***

## 州

使用以下参数从特定美国州选择代理 `st` 参数。州名称必须包含 `us_` 前缀（例如， `us_california`, `us_illinois`).

```
customer-USERNAME-st-us_california:PASSWORD
```

#### 代码示例

在此示例中，对 `ip.oxylabs.io/location` 的查询是从美国加利福尼亚州的随机 IP 地址发起的：

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

```shell
curl -x pr.oxylabs.io:7777 -U "customer-USERNAME-st-us_california:PASSWORD" https://ip.oxylabs.io/location
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$username = 'USERNAME';
$password = 'PASSWORD';
$state = 'us_california';
$proxy = 'pr.oxylabs.io:7777';
$query = curl_init('https://ip.oxylabs.io/location');
curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_PROXY, "http://$proxy");
curl_setopt($query, CURLOPT_PROXYUSERPWD, "customer-$username-st-$state:$password");
$output = curl_exec($query);
curl_close($query);
if ($output)
    echo $output;
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import urllib.request
import random
用户名 = 'USERNAME'
password = 'PASSWORD'
state = 'us_california'
entry = ('http://customer-%s-st-%s:%s@pr.oxylabs.io:7777' %
    (username, state, password))
query = urllib.request.ProxyHandler({
    'http': entry,
    'https': entry,
})
execute = urllib.request.build_opener(query)
print(execute.open('https://ip.oxylabs.io/location').read())
```

{% endtab %}

{% tab title="Java" %}

```java
package example;

import org.apache.http.HttpHost;
import org.apache.http.client.fluent.*;

public class Example {
    public static void main(String[] args) throws Exception {
        HttpHost entry = new HttpHost("pr.oxylabs.io", 7777);
        String query = Executor.newInstance()
            .auth(entry, "customer-USERNAME-st-us_california", "PASS")
            .execute(Request.Get("http://ip.oxylabs.io/location").viaProxy(entry))
            .returnContent().asString();
        System.out.println(query);
    }
}
```

{% endtab %}

{% tab title="C#" %}

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

class Example
{
    static void Main()
    {
        var client = new WebClient();
        client.Proxy = new WebProxy("pr.oxylabs.io:7777");
        client.Proxy.Credentials = new NetworkCredential("customer-USERNAME-st-us_california", "PASSWORD");
        Console.WriteLine(client.DownloadString("https://ip.oxylabs.io/location"));
    }
}
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'uri'
require 'net/http'

uri = URI.parse('https://ip.oxylabs.io/location')
proxy = Net::HTTP::Proxy('pr.oxylabs.io', 7777, 'customer-USERNAME-st-us_california', 'PASSWORD')

req = Net::HTTP::Get.new(uri.path)

result = proxy.start(uri.host,uri.port) do |http|
    http.request(req)
end

```

{% endtab %}
{% endtabs %}

请参见下面的完整支持州列表：

{% file src="/files/a76d312b21a7061f804402d070e8d1ac3ffea023" %}

***

## 洲

使用以下参数将请求路由到七大洲中的任意一洲 `cn` 参数，后跟两字母洲代码：

`cn-AF` – 非洲\
`cn-AN` – 南极洲\
`cn-AS` – 亚洲\
`cn-EU` – 欧洲\
`cn-NA` – 北美洲\
`cn-OC` – 大洋洲\
`cn-SA` – 南美洲

```
customer-USERNAME-cn-EU:PASSWORD
```

#### 代码示例

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

```shell
curl -x pr.oxylabs.io:7777 -U "customer-USERNAME-cn-AS:PASSWORD" https://ip.oxylabs.io/location
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$username = 'USERNAME';
$password = 'PASSWORD';
$continent = 'AS';
$proxy = 'pr.oxylabs.io:7777';
$query = curl_init('https://ip.oxylabs.io/location');
curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_PROXY, "http://$proxy");
curl_setopt($query, CURLOPT_PROXYUSERPWD, "customer-$username-cn-$continent:$password");
$output = curl_exec($query);
curl_close($query);
if ($output)
    echo $output;
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import urllib.request
import random
用户名 = 'USERNAME'
password = 'PASSWORD'
continent = 'AS'
entry = ('http://customer-%s-cn-%s:%s@pr.oxylabs.io:7777' %
    (username, continent, password))
query = urllib.request.ProxyHandler({
    'http': entry,
    'https': entry,
})
execute = urllib.request.build_opener(query)
print(execute.open('https://ip.oxylabs.io/location').read())
```

{% endtab %}

{% tab title="Java" %}

```java
package example;

import org.apache.http.HttpHost;
import org.apache.http.client.fluent.*;

public class Example {
    public static void main(String[] args) throws Exception {
        HttpHost entry = new HttpHost("pr.oxylabs.io", 7777);
        String query = Executor.newInstance()
            .auth(entry, "customer-USERNAME-cn-AS", "PASS")
            .execute(Request.Get("http://ip.oxylabs.io/location").viaProxy(entry))
            .returnContent().asString();
        System.out.println(query);
    }
}
```

{% endtab %}

{% tab title="C#" %}

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

class Example
{
    static void Main()
    {
        var client = new WebClient();
        client.Proxy = new WebProxy("pr.oxylabs.io:7777");
        client.Proxy.Credentials = new NetworkCredential("customer-USERNAME-cn-AS", "PASSWORD");
        Console.WriteLine(client.DownloadString("https://ip.oxylabs.io/location"));
    }
}
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'uri'
require 'net/http'

uri = URI.parse('https://ip.oxylabs.io/location')
proxy = Net::HTTP::Proxy('pr.oxylabs.io', 7777, 'customer-USERNAME-cn-AS', 'PASSWORD')

req = Net::HTTP::Get.new(uri.path)

result = proxy.start(uri.host,uri.port) do |http|
    http.request(req)
end

puts result.body
```

{% endtab %}
{% endtabs %}

***

## ZIP / 邮政编码

使用以下参数定位特定的美国 5 位 ZIP 代码 `postalcode` 参数。该参数必须与国家代码参数 `cc` 以及不区分大小写的 2 位 [**3166-1 alpha-2 格式**](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).

{% hint style="info" %}
目前我们支持 **仅支持美国代码** 用于 ZIP 代码定位时，该参数 **必须搭配** `cc-US`.
{% endhint %}

```
customer-USERNAME-cc-US-postalcode-90210:PASSWORD
```

#### 代码示例

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

```shell
curl -x pr.oxylabs.io:7777 -U "customer-USERNAME-cc-US-postalcode-90210:PASSWORD" https://ip.oxylabs.io/location
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$username = 'USERNAME';
$password = 'PASSWORD';
$country = 'US';
$postalcode = '90210';
$proxy = 'pr.oxylabs.io:7777';
$query = curl_init('https://ip.oxylabs.io/location');
curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_PROXY, "http://$proxy");
curl_setopt($query, CURLOPT_PROXYUSERPWD, "customer-$username-cc-$country-postalcode-$postalcode:$password");
$output = curl_exec($query);
curl_close($query);
if ($output)
    echo $output;
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import urllib.request
import random
用户名 = 'USERNAME'
password = 'PASSWORD'
country = 'US'
postalcode = '90210'
entry = ('http://customer-%s-cc-%s-postalcode-%s:%s@pr.oxylabs.io:7777' %
    (username, country, postalcode, password))
query = urllib.request.ProxyHandler({
    'http': entry,
    'https': entry,
})
execute = urllib.request.build_opener(query)
print(execute.open('https://ip.oxylabs.io/location').read())
```

{% endtab %}

{% tab title="Java" %}

```java
package example;

import org.apache.http.HttpHost;
import org.apache.http.client.fluent.*;

public class Example {
    public static void main(String[] args) throws Exception {
        HttpHost entry = new HttpHost("pr.oxylabs.io", 7777);
        String query = Executor.newInstance()
            .auth(entry, "customer-USERNAME-cc-US-postalcode-90210", "PASS")
            .execute(Request.Get("https://ip.oxylabs.io/location").viaProxy(entry))
            .returnContent().asString();
        System.out.println(query);
    }
}
```

{% endtab %}

{% tab title="C#" %}

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

class Example
{
    static void Main()
    {
        var client = new WebClient();
        client.Proxy = new WebProxy("pr.oxylabs.io:7777");
        client.Proxy.Credentials = new NetworkCredential("customer-USERNAME-cc-US-postalcode-90210", "PASSWORD");
        Console.WriteLine(client.DownloadString("https://ip.oxylabs.io/location"));
    }
}
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'uri'
require 'net/http'

uri = URI.parse('https://ip.oxylabs.io/location')
proxy = Net::HTTP::Proxy('pr.oxylabs.io', 7777, 'customer-USERNAME-cc-US-postalcode-90210', 'PASSWORD')

req = Net::HTTP::Get.new(uri.path)

result = proxy.start(uri.host,uri.port) do |http|
    http.request(req)
end

puts result.body
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
使用 ZIP 代码的代理位置是通过 [**MaxMind IP Geolocation**](https://www.maxmind.com/en/geoip-demo) 数据库匹配的。在将 IP 地址与其他 IP 地理位置数据库进行比对时，ZIP 代码可能会不一致。
{% endhint %}

***

## Geohash

使用从第 1 级（最大）到第 4 级（最小）的 geohash 代码，在特定地理网格单元内定位代理。Geohash 可在不依赖国家或城市边界等传统行政边界的情况下，实现精确的基于网格的定位。

默认情况下，geohash 使用严格定位：如果请求的单元中没有可用 IP，请求将返回一个 `502 Bad Gateway` 错误。

```
customer-USERNAME-geohash-u09:PASSWORD
```

<table><thead><tr><th width="79">长度</th><th width="205.69921875">单元大小约为</th><th>示例</th></tr></thead><tbody><tr><td>1</td><td>≤ 5,000 km × 5,000 km</td><td><code>geohash-9</code> （美国和墨西哥的大部分地区）， <code>geohash-c</code> （美国北部和加拿大）</td></tr><tr><td>2</td><td>≤ 1,250 km × 625 km</td><td><code>geohash-gc</code> （爱尔兰、北爱尔兰、英格兰和苏格兰）</td></tr><tr><td>3</td><td>≤ 156 km × 156 km</td><td><code>geohash-u09</code> （巴黎）</td></tr><tr><td>4</td><td>≤ 39.1 km × 19.5 km</td><td><code>geohash-drq4</code> （楠塔基特岛的大部分地区）</td></tr></tbody></table>

#### 代码示例

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

```shell
curl -x pr.oxylabs.io:7777 -U "customer-USERNAME-geohash-u09:PASSWORD" https://ip.oxylabs.io/location
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$username = 'USERNAME';
$password = 'PASSWORD';
$geohash = 'u09';
$proxy = 'pr.oxylabs.io:7777';
$query = curl_init('https://ip.oxylabs.io/location');
curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_PROXY, "http://$proxy");
curl_setopt($query, CURLOPT_PROXYUSERPWD, "customer-$username-geohash-$geohash:$password");
$output = curl_exec($query);
curl_close($query);
if ($output)
    echo $output;
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import urllib.request
import random
用户名 = 'USERNAME'
password = 'PASSWORD'
geohash = 'u09'
entry = ('http://customer-%s-geohash-%s:%s@pr.oxylabs.io:7777' %
    (username, geohash, password))
query = urllib.request.ProxyHandler({
    'http': entry,
    'https': entry,
})
execute = urllib.request.build_opener(query)
print(execute.open('https://ip.oxylabs.io/location').read())
```

{% endtab %}

{% tab title="Java" %}

```java
package example;

import org.apache.http.HttpHost;
import org.apache.http.client.fluent.*;

public class Example {
    public static void main(String[] args) throws Exception {
        HttpHost entry = new HttpHost("pr.oxylabs.io", 7777);
        String query = Executor.newInstance()
            .auth(entry, "customer-USERNAME-geohash-u09", "PASS")
            .execute(Request.Get("http://ip.oxylabs.io/location").viaProxy(entry))
            .returnContent().asString();
        System.out.println(query);
    }
}
```

{% endtab %}

{% tab title="C#" %}

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

class Example
{
    static void Main()
    {
        var client = new WebClient();
        client.Proxy = new WebProxy("pr.oxylabs.io:7777");
        client.Proxy.Credentials = new NetworkCredential("customer-USERNAME-geohash-u09", "PASSWORD");
        Console.WriteLine(client.DownloadString("https://ip.oxylabs.io/location"));
    }
}
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'uri'
require 'net/http'

uri = URI.parse('https://ip.oxylabs.io/location')
proxy = Net::HTTP::Proxy('pr.oxylabs.io', 7777, 'customer-USERNAME-geohash-u09', 'PASSWORD')

req = Net::HTTP::Get.new(uri.path)

result = proxy.start(uri.host,uri.port) do |http|
    http.request(req)
end

puts result.body

```

{% endtab %}
{% endtabs %}

### Geohash 回退

{% hint style="warning" %}
`地理哈希` 和 `geohash_fallback` 彼此互斥，也与其他地理位置参数互斥，例如 `cc` （country）， `city`, `st` （state）， `cn` （continent），以及 `postalcode`.
{% endhint %}

如果你的使用场景不需要严格的单元匹配， `geohash_fallback` 系统会使用轮换器，每次自动删除一个 geohash 字符，逐步扩大区域，直到找到可用的代理。&#x20;

如果在单字符级别找不到 IP， `502 Bad Gateway` 将返回错误。

```
customer-USERNAME-geohash_fallback-2svd:PASSWORD
```

* **初始目标：** `2svd` （≤ 39.1 km × 19.5 km）
* **回退 1（移除 1 个字符）：** `2sv` （≤ 156 km × 156 km）
* **回退 2（移除 2 个字符）：** `2s` （≤ 1,250 km × 625 km）
* **回退 3（移除 3 个字符）：** `2` （≤ 5,000 km × 5,000 km）

{% hint style="info" %}
**跟踪回退：** 所使用的 geohash 单元会在 `x-geo-hash-fallback` 响应头中返回。将其与请求值比较，可查看是否发生回退以及区域扩展了多少。
{% endhint %}

#### 代码示例

```shellscript
curl -v -x pr.oxylabs.io:7777 -U "customer-USERNAME-geohash_fallback-2svd:PASSWORD" https://ip.oxylabs.io/location
```

***

## ASN 定位

使用自治系统编号（`ASN`）。你可以找到 ASN 编号 [**这里**](https://asnlookup.com/)**.**

```
customer-USERNAME-ASN-21928-sessid-abcde12345:PASSWORD
```

如果指定的 ASN 没有可用的活跃代理，请求将返回一个 `502 Bad Gateway` 错误。

{% hint style="warning" %}
从某些 ASN 访问住宅代理可能会返回一个 `403 Access denied: restricted ASN` 错误，如果你的 Oxylabs 账户尚未完成 KYC 验证。 [联系支持](mailto:support@oxylabs.io) 以完成 KYC 流程。
{% endhint %}

{% hint style="info" %}
每个请求只能使用 Country 或 ASN 参数之一。如果同时使用这两个位置参数，则只会应用 Country 参数。
{% endhint %}

***

## 坐标

使用以下内容，将代理定位到特定地理坐标附近： `X-Oxylabs-Geolocation` HTTP 代理头。值格式为 `纬度:经度;半径` （半径以英里为单位，最小 10 英里）。

```
X-Oxylabs-Geolocation: 49.9235:-97.0811;10
```

{% hint style="info" %}
如果在提供的坐标和半径内找不到 IP，您将收到 `502` 响应代码。请参阅完整的响应代码列表 [**这里**](https://developers.oxylabs.io/products/cn/proxies/residential-proxies/additional-information.md).
{% endhint %}

#### 代码示例

```bash
curl -x pr.oxylabs.io:7777 -U "customer-USERNAME:PASSWORD" --proxy-header "X-Oxylabs-Geolocation: 49.9235:-97.0811;10" https://ip.oxylabs.io/location
```

## 中国入口节点

对于从中国大陆发起的请求，专用的 HTTPS 区域入口节点可提供优化的连接。

* **香港：** `a81298871.com:8000`
* **北京：** `cnt9t1is.com:8000`

```bash
curl -x cnt9t1is.com:8000 -U "customer-USERNAME-cc-US:PASSWORD" https://ip.oxylabs.io/location
```

{% hint style="warning" %}
**注意：** 某些第三方工具可能无法与香港和北京入口节点配合使用。已确认可正常工作的工具包括 [Oxy Proxy Extension for Chrome](https://developers.oxylabs.io/integrations/proxy-integrations/oxy-proxy-extension-for-chrome), [SwitchyOmega](https://developers.oxylabs.io/integrations/proxy-integrations/switchyomega)，以及 [Shadowrocket](https://developers.oxylabs.io/integrations/proxy-integrations/shadowrocket)。我们目前正在为 HTTPS 协议支持更多集成。

如果你从中国连接到我们的住宅网络后仍然遇到提供的入口节点问题，请通过 [**support@oxylabs.io**](mailto:support@oxylabs.io) 联系我们以获得更多帮助。
{% 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/residential-proxies/location-settings.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.
