# 使用代理字符串

在本节中，我们将展示使用我们创建的代理字符串的实际示例。我们将重点介绍如何设置HTTP/HTTPS和SOCKS5连接，并通过使用各种编程语言的示例进行说明。

我们的数据中心代理兼容UDP和TCP连接

{% hint style="warning" %}
请记住，端口会根据协议（**HTTP/SOCKS5**）而有所不同。要想在HTTP或SOCKS5代理之间进行选择，请参阅“订单配置”部分中的“格式化代理列表”面板。\
\
[ding-dan-pei-zhi](https://docs.iproyal.com/cn/dai-li/jing-tai-zhu-zhai-dai-li/yi-biao-ban/ding-dan-pei-zhi "mention")
{% endhint %}

### HTTP/HTTPS

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

```bash
curl -v -x http://45.12.106.20:12323 --proxy-user 1a725103c093:d510a22638 -L https://ipv4.icanhazip.com
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$url = 'https://ipv4.icanhazip.com';
$proxy = '45.12.106.20:12323';
$proxyAuth = '1a725103c093:d510a22638';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$response = curl_exec($ch);
curl_close($ch);

echo $response;

?>
```

{% endtab %}

{% tab title="JS" %}

```javascript
const axios = require('axios');

const url = 'https://ipv4.icanhazip.com';
const proxyOptions = {
  host: '45.12.106.20',
  port: 12323,
  auth: {
    username: '1a725103c093',
    password: 'd510a22638'
  }
};

axios.get(url, { proxy: proxyOptions })
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error('Error:', error);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = 'https://ipv4.icanhazip.com'
proxy = '45.12.106.20:12323'
proxy_auth = '1a725103c093:d510a22638'
proxies = {
    'http': f'http://{proxy_auth}@{proxy}',
    'https': f'http://{proxy_auth}@{proxy}'
}

response = requests.get(url, proxies=proxies)
print(response.text)
```

{% endtab %}
{% endtabs %}

### SOCKS5

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

```bash
curl -v --socks5 45.12.106.20:12324 --proxy-user 1a725103c093:d510a22638 -L https://ipv4.icanhazip.com
```

{% endtab %}

{% tab title="PHP" %}

<pre class="language-php"><code class="lang-php"><strong>&#x3C;?php
</strong>
$url = 'https://ipv4.icanhazip.com';
$proxy = '45.12.106.20:12324';
$proxyAuth = '1a725103c093:d510a22638';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$response = curl_exec($ch);
curl_close($ch);

echo $response;

?>
</code></pre>

{% endtab %}

{% tab title="JS" %}

```javascript
const axios = require('axios');
const SocksProxyAgent = require('socks-proxy-agent');

const url = 'https://ipv4.icanhazip.com';
const socksProxy = 'socks5://1a725103c093:d510a22638@45.12.106.20:12324';
const agent = new SocksProxyAgent(socksProxy);

axios.get(url, { httpAgent: agent, httpsAgent: agent })
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error('Error:', error);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = 'https://ipv4.icanhazip.com'
socks5_proxy = 'socks5://1a725103c093:d510a22638@45.12.106.20:12324'
proxies = {
    'http': socks5_proxy,
    'https': socks5_proxy
}

response = requests.get(url, proxies=proxies)
print(response.text)
```

{% endtab %}
{% endtabs %}


---

# 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://docs.iproyal.com/cn/dai-li/shu-ju-zhong-xin-dai-li/shi-yong-dai-li-zi-fu-chuan.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.
