> For the complete documentation index, see [llms.txt](https://doc.thordata.com/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.thordata.com/doc/zh/proxies/residential-proxies/location-settings/city.md).

# 城市

我们支持将IP精准至城市级定位，只需要使用`city参数`。例如：`country-US-city-houston`表示来自美国休斯顿的IP。

{% hint style="success" %}
[**点击此处**](https://vip-upload.thordata.com/files/file/residential-proxies/list_of_city_zh.xlsx)下载完整的城市列表。

我们愿意为全球范围内的任何城市提供支持，但我们不保证在所有城市都设有代理。在大多数热门城市中，我们的覆盖率良好，并且提供了诸多代理选择。
{% endhint %}

以下是一些城市参数的有效示例：

| 国家-城市  | 国家-城市参数                   |
| ------ | ------------------------- |
| 德国-慕尼黑 | `country-DE-city-munich`  |
| 印度-新德里 | `country-IN-city-delhi`   |
| 泰国-曼谷  | `country-TH-city-bangkok` |
| 韩国-首尔  | `country-KR-city-seoul`   |
| 日本-东京  | `country-JP-city-tokyo`   |

**代码示例：**

使用来自美国休斯顿的随机IP地址对`ipinfo.thordata.com`执行查询

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

```sh
curl -x t.pr.thordata.net:9999 -U "td-customer-USERNAME-country-US-city-houston:PASSWORD" ipinfo.thordata.com
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class csharp_http_region
{
    static void Main(string[] args)
    {
        Task t = new Task(DownloadPageAsync);
        t.Start();
        Console.ReadLine();
    }

    static async void DownloadPageAsync()
    {
        string page = "https://ipinfo.thordata.com";

        String username = "username";
        String password = "password";
        String country = "us";
        String city = "houston";
        String proxyUserName = $"td-customer-{username}-country-{country}-city-{city}";


        var proxy = new WebProxy("http://t.pr.thordata.net:9999")
        {
            UseDefaultCredentials = false,

            Credentials = new NetworkCredential(
                userName: proxyUserName,
                password: password)
        };

        var httpClientHandler = new HttpClientHandler()
        {
            Proxy = proxy,
        };

        var client = new HttpClient(handler: httpClientHandler, disposeHandler: true);
        var response = await client.GetAsync(page);
        using (HttpContent content = response.Content)
        {
            string result = await content.ReadAsStringAsync();
            Console.WriteLine(result);
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();

        }
    }
}
```

{% endtab %}

{% tab title="Go" %}

```go
package main

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

const (
	resourceUrl = "https://ipinfo.thordata.com"
	proxyHost   = "t.pr.thordata.net:9999"
	username    = "username"
	password    = "password"
	country     = "us"
	city        = "houston"
)

func main() {
	proxyUserName := fmt.Sprintf("td-customer-%s-country-%s-city-%s", username, country, city)
	proxyUrl := &url.URL{
		Scheme: "http",
		User:   url.UserPassword(proxyUserName, password),
		Host:   proxyHost,
	}

	client := http.Client{
		Transport: &http.Transport{
			Proxy: http.ProxyURL(proxyUrl),
		},
	}

	resp, err := client.Get(resourceUrl)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}

	bodyString := string(body)
	fmt.Println(bodyString)
}
```

{% endtab %}

{% tab title="Java" %}

```java
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class JavaHttpRegionCity {
    public static final String username = "username";
    public static final String password = "password";
    public static final int port = 9999;

    public static final String region = "us";
    public static final String city = "houston";
    public static final String proxyHost = "t.pr.thordata.net";

    public static final String proxyname = String.format("td-customer-%s-country-%s-city-%s", username, region,city);
    public CloseableHttpClient client;


    public JavaHttpRegionCity() {
        HttpHost proxy = new HttpHost(proxyHost, port);
        CredentialsProvider cred_provider = new BasicCredentialsProvider();
        cred_provider.setCredentials(new AuthScope(proxy),
                new UsernamePasswordCredentials(proxyname, password));
        client = HttpClients.custom()
                .setConnectionManager(new BasicHttpClientConnectionManager())
                .setProxy(proxy)
                .setDefaultCredentialsProvider(cred_provider)
                .build();
    }

    public String request(String url) throws IOException {
        HttpGet request = new HttpGet(url);
        CloseableHttpResponse response = client.execute(request);
        try {
            return EntityUtils.toString(response.getEntity());
        } finally { response.close(); }
    }

    public void close() throws IOException { client.close(); }

    public static void main(String[] args) throws IOException {
        JavaHttpRegionCity client = new JavaHttpRegionCity();
        try {
            System.out.println(client.request("https://ipinfo.thordata.com"));
        } finally { client.close(); }
    }
}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
  $url = 'ipinfo.thordata.com';
  $proxy = 't.pr.thordata.net';
  $port = 9999;
  $user = 'username';
  $psw = 'password';
  $country = 'us';
  $city = 'houston';
  $proxyuser = sprintf("td-customer-%s-country-%s-city-%s",$user,$country,$city);


  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  
  curl_setopt($ch, CURLOPT_PROXY, "$proxy:$port");
  curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$proxyuser:$psw");
  $result = curl_exec($ch);
  curl_close($ch);
  
  if ($result)
  {
      echo $result . PHP_EOL;
  }
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

username = "username"
password = "password"
proxy_server = "t.pr.thordata.net:9999"
country = "us"
city = "houston"

proxies = {
    "http": f"http://td-customer-{username}-country-{country}-city-{city}:{password}@{proxy_server}"
}
response = requests.get("http://ipinfo.thordata.com", proxies=proxies)
print(response.text)
```

{% endtab %}

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

```
const rp = require('request-promise');

const username = "username";
const password = "password";
const proxyServer = "t.pr.thordata.net:9999";
const country = "us";
const city = "houston";

rp({
    url: 'http://ipinfo.thordata.com',  
    proxy: `http://td-customer-${username}-country-${country}-city-${city}:${password}@${proxyServer}`,  
})
.then(function(data) {
    console.log(data);  
})
.catch(function(err) {
    console.error(err); 
});
```

{% endtab %}

{% tab title="Ruby" %}

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

proxy_host = 't.pr.thordata.net' 
proxy_port = 9999 
proxy_username = 'username'
proxy_pass = 'password'
proxy_country = 'us'
proxy_city = 'houston'
proxy_user = "td-customer-#{proxy_username}-country-#{proxy_country}-city-#{proxy_city}"

uri = URI.parse('https://ipin.thordata.com') 
proxy = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass) 

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

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

puts result.body
```

{% endtab %}
{% endtabs %}

**点击下方**文件查看完整的**城市**列表：

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