> For the complete documentation index, see [llms.txt](https://docs.ipwo.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ipwo.net/kai-fa-zhe-wen-dang/dai-ma-shi-li/rust.md).

# Rust

使用 Rust 可以通过 [IPWO 代理](https://www.ipwo.net/)发起 HTTP 请求，适用于高性能 API 服务、数据采集与异步并发场景。

***

### 一、安装依赖

在 `Cargo.toml` 中添加：

```toml
[dependencies]
reqwest = { version = "0.12", features = ["blocking"] }
```

***

### 二、HTTP 代理示例

```rust
use reqwest::blocking::Client;
use reqwest::Proxy;

fn main() -> Result<(), Box<dyn std::error::Error>> {

    let proxy = Proxy::http(
        "http://username_custom_zone_us:password@us.ipwo.net:7878"
    )?;

    let client = Client::builder()
        .proxy(proxy)
        .timeout(std::time::Duration::from_secs(30))
        .build()?;

    let response = client
        .get("http://ipinfo.io")
        .send()?
        .text()?;

    println!("{}", response);

    Ok(())
}
```

***

### 三、正常返回示例

```json
{
  "ip": "203.0.113.10",
  "country": "US"
}
```

如果返回的 IP：

* 不是本机公网 IP
* 国家地区正确

说明代理已经生效。

***

### 四、异步请求示例（推荐）

在 `Cargo.toml` 中添加：

```toml
[dependencies]
tokio = { version = "1", features = ["full"] }

reqwest = "0.12"
```

***

```rust
use reqwest::{Client, Proxy};

#[tokio::main]

async fn main()
-> Result<(), Box<dyn std::error::Error>> {

    let proxy = Proxy::http(
        "http://username_custom_zone_us:password@us.ipwo.net:7878"
    )?;

    let client = Client::builder()
        .proxy(proxy)
        .timeout(std::time::Duration::from_secs(30))
        .build()?;

    let response = client
        .get("http://ipinfo.io")
        .send()
        .await?
        .text()
        .await?;

    println!("{}", response);

    Ok(())
}
```

***

### 五、常见问题

#### [407 Proxy Authentication Required](/kai-fa-zhe-wen-dang/chang-jian-cuo-wu/407-proxy-authentication-required.md)

通常是：

* 用户名错误
* 密码错误
* zone 参数错误

***

#### [Timeout 超时](/kai-fa-zhe-wen-dang/chang-jian-cuo-wu/chao-shi-timeout.md)

通常是：

* 网络环境异常
* DNS 问题
* 请求超时时间过短

***

#### [Connection reset](/kai-fa-zhe-wen-dang/chang-jian-cuo-wu/connection-reset.md)

高并发场景可能出现：

```
连接被远程服务器中断
```

建议：

* 增加 Retry
* 控制并发数量

***

### 六、推荐开发建议

推荐：

* 使用海外 VPS
* 增加 timeout
* 使用异步请求
* 增加 Retry 重试机制
* 使用粘性 Session

适用于：

* 高性能 API
* 数据采集
* 并发请求
* AI 数据处理

***

### 七、相关文章

* [Go](/kai-fa-zhe-wen-dang/dai-ma-shi-li/go.md)
* [Python Requests](/kai-fa-zhe-wen-dang/dai-ma-shi-li/python/requests.md)
* [HTTPX](/kai-fa-zhe-wen-dang/dai-ma-shi-li/python/httpx.md)
* [API 调用与批量采集](/dai-li-ji-chu-zhi-shi/api-diao-yong-yu-pi-liang-cai-ji.md)
* [超时 Timeout](/kai-fa-zhe-wen-dang/chang-jian-cuo-wu/chao-shi-timeout.md)
* [什么是粘性会话](/dai-li-ji-chu-zhi-shi/shen-me-shi-nian-xing-hui-hua.md)


---

# 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://docs.ipwo.net/kai-fa-zhe-wen-dang/dai-ma-shi-li/rust.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.
