> 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/making-requests.md).

# 发起请求

学习使用住宅代理发起请求。掌握基本查询结构，并使用参数进行位置定向、城市选择和会话控制。

## **基础查询**

基础查询只需传入 `用户名` 和 `密码`。无需其他参数。此类查询会使请求从随机 IP 地址发出（代理）。每个新请求都会使用不同的代理。

## 代码示例

在此示例中，对 `ip.oxylabs.io/location` 是从随机 IP 发起的：

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

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

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$username = 'USERNAME';
$password = 'PASSWORD';
$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:$password");
$output = curl_exec($query);
curl_close($query);
if ($output)
    echo $output;
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import urllib.request
import random
username = 'USERNAME'
password = 'PASSWORD'
entry = ('http://customer-%s:%s@pr.oxylabs.io:7777' %
    (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("pr.oxylabs.io", 7777);
        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("pr.oxylabs.io:7777");
        client.Proxy.Credentials = new NetworkCredential("customer-USERNAME", "PASSWORD");
        Console.WriteLine(client.DownloadString("https://ip.oxylabs.io/location"));
    }
c
```

{% 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', '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 %}

单个回连代理（`pr.oxylabs.io:7777）`允许你通过用户名中的附加参数选择特定国家或城市的代理。此方法还支持会话控制。以下是凭据示例：

`customer-USERNAME-cc-US-city-CITY-sessid-abcde12345:PASSWORD`

`customer-USERNAME-cc-US-city-CITY-sessid-abcde12345-sesstime-5:PASSWORD`

以下是结构分解：

<figure><img src="https://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%2Fuploads%2Fgit-blob-d3f1a59d25a42e887f472219825623641de0ef3b%2FCode%20explained%20for%20Resi%20documentation%20(upd%202025-06).png?alt=media" alt=""><figcaption></figcaption></figure>

## 查询参数

<table><thead><tr><th width="147">参数</th><th>说明</th></tr></thead><tbody><tr><td><mark style="background-color:green;"><strong><code>customer</code></strong></mark></td><td>用户名</td></tr><tr><td><code>cc</code></td><td>不区分大小写的两位字母国家代码，采用 <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2"><strong>3166-1 alpha-2 格式</strong></a>。例如， <code>DE</code> 表示德国， <code>GB</code> 表示英国， <code>TH</code> 表示泰国。你可以在此了解更多有关如何使用按国家定向的代理的信息 <a href="/products/cn/proxies/residential-proxies/location-settings/select-country.md"><strong>这里</strong></a>.</td></tr><tr><td><code>city</code></td><td>不区分大小写的英文城市名称。此参数必须与 <code>cc</code> 一起使用以提高准确性，例如， <code>cc-GB-city-london</code> 表示英国伦敦； <code>cc-DE-city-berlin</code> 表示德国柏林。对于包含两个以上单词的城市名，请将空格替换为 <code>_</code>，例如， <code>city-st_petersburg</code> 或 <code>city-rio_de_janeiro</code>。点击 <a href="/products/cn/proxies/residential-proxies/location-settings/select-city.md"><strong>这里</strong></a> 了解更多关于城市级定向的信息。</td></tr><tr><td><code>st</code></td><td>不区分大小写的美国州名，前缀为 us_，例如， <code>us_california</code>, <code>us_illinois</code>. <a href="/products/cn/proxies/residential-proxies/location-settings/select-state.md"><strong>点击这里</strong> </a>了解更多关于州级定向的信息。</td></tr><tr><td><code>sessid</code></td><td>会话 ID，用于在后续查询中保持相同的 IP。会话在 10 分钟后过期。之后，该会话 ID 将分配新的 IP 地址。支持随机字符串、0-9 和 A-Z 字符。</td></tr><tr><td><code>sesstime</code></td><td>会话时间参数可在指定时间内保持相同的 IP。最长会话时间为 30 分钟。</td></tr><tr><td><mark style="background-color:green;"><strong><code>密码</code></strong></mark></td><td>密码</td></tr></tbody></table>

&#x20;   \- 必填参数

## 中国入口节点

```
https://a81298871.com:8000 - 香港
```

```
https://cnt9t1is.com:8000 - 北京
```

我们已在香港和北京区域配置入口节点，以便从中国获得更好的连接。请注意，这是一个 HTTPS 代理节点。所有用户名参数与常规入口节点相同。

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

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

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$username = 'USERNAME';
$password = 'PASSWORD';
$proxy = 'cnt9t1is.com:8000';
$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 = 'USERNAME'
password = 'PASSWORD'
entry = ('http://customer-%s:%s@cnt9t1is.com:8000' %
    (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("cnt9t1is.com", 8000);
        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("cnt9t1is.com:8000");
        client.Proxy.Credentials = new NetworkCredential("customer-USERNAME", "PASSWORD");
        Console.WriteLine(client.DownloadString("https://ip.oxylabs.io/location"));
    }
c
```

{% endtab %}

{% tab title="Ruby" %}

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

uri = URI.parse('https://ip.oxylabs.io/location')
proxy = Net::HTTP::Proxy('cnt9t1is.com', 8000, '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 %}

请注意，目前某些第三方工具无法与香港和北京入口节点配合使用。可与这些入口节点配合使用的第三方工具有：

1. [**Chrome 的 Oxy Proxy 扩展**](/integrations/cn/proxy-integrations/oxy-proxy-extension-for-chrome.md)
2. [**SwitchyOmega**](/integrations/cn/proxy-integrations/switchyomega.md)
3. [**Shadowrocket**](/integrations/cn/proxy-integrations/shadowrocket.md)

我们正在修复其余集成，届时将支持 HTTPS 协议。

如果你从中国连接我们的住宅网络，且使用所提供的入口节点仍有问题，请联系 [**support@oxylabs.io**](mailto:support@oxylabs.io)，我们会一起想办法解决。


---

# 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 dynamically by asking a question.

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

```
GET https://developers.oxylabs.io/products/cn/proxies/residential-proxies/making-requests.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
