小编bro*_*hjt的帖子

如何将超响应正文写入文件?

我正在尝试使用 tokio 编写一个测试程序,该程序从网站上获取文件并将流式响应写入文件。超级网站显示了一个示例,该示例使用 while 循环并使用.data()响应主体的方法,但我想与.map()其他几个人一起操作流。

我认为下一个合理的尝试是AsyncRead使用.into_async_read()from 方法将流转换为 an TryStreamExt,但这似乎不起作用。我不得不使用地图将 the 转换hyper::error::Error为 astd::error::Error以获取 a TryStream,但现在编译器告诉我AsyncRead没有为转换后的流实现。这是我的 main.rs 文件和错误:

src/main.rs

use futures::stream::{StreamExt, TryStreamExt};
use http::Request;
use hyper::{Body, Client};
use hyper_tls::HttpsConnector;
use tokio::fs::File;
use tokio::io;

use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let https = HttpsConnector::new();
    let client = Client::builder().build::<_, Body>(https);

    let request = Request::get("some file from the internet").body(Body::empty())?;
    let response = client.request(request).await?;

    let …
Run Code Online (Sandbox Code Playgroud)

hyper rust-tokio

6
推荐指数
1
解决办法
779
查看次数

标签 统计

hyper ×1

rust-tokio ×1