# 发送请求

### **基本查询**

基本查询仅需要输入`USERNAME`和`PASSWORD`，无需其他任何参数。对于基本查询，是通过随机IP地址发送请求，每次新的请求都会使用不同的代理。

**代码示例：**

在下方示例中，通过随机IP执行对`ipinfo.thordata.com`的查询

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

```sh
curl -x "https://td-customer-USERNAME:PASSWORD@t.pr.thordata.net:5555" "https://ipinfo.thordata.com"
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

class csharp_https
{
    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("https://t.pr.thordata.net:5555")
        {
            UseDefaultCredentials = false,
            Credentials = new NetworkCredential(
                userName: "td-customer-USERNAME",
                password: "PASSWORD")
        };

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

        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:5555"
	username    = "td-customer-USERNAME"
	password    = "PASSWORD"
)

func main() {
	proxyUrl := &url.URL{
		Scheme: "https",
		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 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 JavaHttps {
    public static final String username = "td-customer-USERNAME";
    public static final String password = "PASSWORD";
    public static final int port = 5555;
    public static final String proxyHost = "t.pr.thordata.net";
    public CloseableHttpClient client;

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


```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
  $url = 'http://ipinfo.thordata.com';
  $proxy = 't.pr.thordata.net';
  $port = 5555;
  $user = 'td-customer-USERNAME';
  $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"
password = "PASWORD"
proxy_server = "t.pr.thordata.net:5555"

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";
const password = "PASSWORD";
const proxyServer = "t.pr.thordata.net:5555";

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.pr.thordata.net'
proxy_port = 5555
proxy_user = 'td-customer-USERNAME'
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 %}

### **特定请求**

Thordata支持在用户名中**添加定位与会话参数**，以指定代理的大洲、国家/地区来源或控制会话行为。

**代码示例**：

使用来自澳大利亚墨尔本的代理，并设置 10 分钟的粘性会话：

```sh
curl -x "http://td-customer-USERNAME-country-au-state-victoria-city-melbourne-sessid-au123-sesstime-10:PASSWORD@t.na.thordata.net:5555" "https://ipinfo.thordata.com"
```

### **查询参数**

| username  | 代理帐户用户名                              | td-customer-username    |
| --------- | ------------------------------------ | ----------------------- |
| continent | 大洲，随机地区无此参数                          | continent-asia          |
| country   | 国家/地区，随机地区无此参数                       | country-au（ 2 个字母的国家代码） |
| state     | 州，随机地区无此参数                           | state-victoria          |
| city      | 您要指定的城市。可以不带“state”参数使用              | city-melbourne          |
| session   | 粘性 IP 和IP 所需。在固定 IP 或切换时查找特定 IP 时使用它 | sessid-au123456         |
| sessTime  | 与会话一起使用来设置 IP 持续时间，最长时间为 **90**分钟    | sessTime-5              |
| password  | 代理账户密码                               | password                |
| asn       | 指定国家的ISP运营商，随机无此参数                   | asn-AS1221              |


---

# 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/proxies/yi-dong-dai-li/fa-song-qing-qiu.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.
