# 州

Thordata支持用戶在代理路由中設置`state`參數，通過**指定州級行政區的住宅IP**傳輸，實現精準定位。示例：`country-us-state-alabama`表示從美國亞拉巴馬州獲取代理。

{% hint style="success" %}
[**點擊此處**](https://vip-upload.thordata.com/files/file/list_of_states.xlsx)下載完整的州列表。
{% endhint %}

{% hint style="danger" %}
必須與`country`參數一起使用`state`參數，單獨使用`state`參數無法獲取指定國家州的IP。
{% endhint %}

以下是一組**國家**和**州**參數的示例組合：

| 国家-州     | 参数                             |
| -------- | ------------------------------ |
| 美國加利福尼亞州 | `country-us-state-california:` |
| 英國英格蘭    | `country-gb-state-england`     |
| 泰國蘇林     | `country-th-state-surin`       |
| 香港九龍城    | `country-hk-state-kowloonc`    |
| 澳大利亞維多利亞 | `country-au-state-victoria`    |

**代碼示例：**

使用來自美國加利福尼亞州的隨機 IP 地址對 `ipinfo.thordata.com` 執行查詢

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

```sh
curl -x "https://td-customer-USERNAME-country-us-state-california:PASSWORD@t.na.thordata.net:9999" "https://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
{
    static void Main(string[] args)
    {
        Task t = new Task(DownloadPageAsync);
        t.Start();
        Console.ReadLine();
    }

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

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

            Credentials = new NetworkCredential(
                userName: "td-customer-USERNAME-country-us-state-california",
                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.na.thordata.net:9999"
	username    = "td-customer-USERNAME-country-us-state-california"
	password    = "PASSWORD"
)

func main() {
	proxyUrl := &url.URL{
		Scheme: "http",
		User:   url.UserPassword(username, 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 java.io.*;
import org.apache.http.HttpHost;
import org.apache.http.auth.*;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.*;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;

public class JavaHttp {
    public static final String username = "td-customer-USERNAME-country-us-state-california";
    public static final String password = "PASSWORD";
    public static final int port = 9999;
    public static final String proxyHost = "t.na.thordata.net";
    public CloseableHttpClient client;

    public JavaHttp() {
        HttpHost proxy = new HttpHost(proxyHost, port);
        CredentialsProvider cred_provider = new BasicCredentialsProvider();
        cred_provider.setCredentials(new AuthScope(proxy),
                new UsernamePasswordCredentials(username, 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 {
        JavaHttp client = new JavaHttp();
        try {
            System.out.println(client.request("https://ipinfo.thordata.com"));
        } finally { client.close(); }
    }
}


```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
  $url = 'https://ipinfo.thordata.com';
  $proxy = 't.na.thordata.net';
  $port = 9999;
  $user = 'td-customer-USERNAME-country-us-state-california';
  $psw = 'PASSWORD';

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($ch, CURLOPT_PROXY, "$proxy:$port");
  curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$user:$psw");
  $result = curl_exec($ch);
  curl_close($ch);

  if ($result)
  {
      echo $result . PHP_EOL;
  }
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

username = "td-customer-USERNAME-country-us-state-california"
password = "PASSWORD"
proxy_server = "t.na.thordata.net:9999"

proxies = {"https": f"https://{username}:{password}@{proxy_server}"}

response = requests.get("https://ipinfo.thordata.com", proxies=proxies)
print(response.text)
```

{% endtab %}

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

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

const username = "td-customer-USERNAME-country-us-state-california";
const password = "PASSWORD";
const proxyServer = "t.na.thordata.net:9999";

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

```

{% endtab %}

{% tab title="Ruby" %}

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

proxy_host = 't.na.thordata.net'
proxy_port = 9999
proxy_user = 'td-customer-USERNAME-country-us-state-california'
proxy_pass = 'PASSWORD'

uri = URI.parse('https://ipinfo.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, ssl_version: :TLSv1_2) do |http|
  http.request(req)
end

puts result.body
```

{% endtab %}
{% endtabs %}

**點擊下方**檔案查看完整的**州**列表：

{% file src="<https://637457805-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbV8SoKVnOm2o3eQR4D1v%2Fuploads%2FSnTzhSxXU0tVnYFRYQ57%2FGeoMapping%20Database.xlsx?alt=media&token=fdddac20-042a-4279-8861-a0c6bcd32f68>" %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.thordata.com/doc/zh-hk/dai-li/zhu-zhai-dai-li/wei-zhi-she-zhi/zhou.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
