< 返回版块

liuxc0116 发表于 2022-01-06 18:33

Tags:reqwest

我使用reqwest库写了几个GET、POST请求访问后端的服务器,连接超时时间设置的是2s,整个请求超时时间设置为4s。 有时程序执行起来几乎1秒都不到就会收到【error trying to connect: operation timed out】或【sending request for url(xxx): operation timed out】这样的报错。请问大家有遇到过这样的错误吗?都是怎么解决的呢。

评论区

写评论
作者 liuxc0116 2022-01-10 11:58

所有的请求都是下面这样的格式书写的,但是每次出问题都不是固定的某一个请求。

async fn post_ping(pings: PingResultBody) -> Result<AgzRes, reqwest::Error> { let client = reqwest::Client::builder() .timeout(std::time::Duration::from_millis(HTTP_CLIENT_TIMEOUT)) .connect_timeout(std::time::Duration::from_millis(HTTP_CONNECT_TIMEOUT)) .build()?; let res_pops = client .post(format!("{}/connections", server_addr().clone())) .header("Authorization", get_token().as_str()) .header("Content-Type", "application/json") .json(&pings) .send() .await? .json::<AgzRes>() .await?; Ok(res_pops) }

--
👇
c5soft: 多半是服务端的原因吧?reqwest/axum稳定得很,生产中使用reqwest/axum重来没出过问题。把项目源代码发到gitee.com上,大家帮你看看。

c5soft 2022-01-08 09:23

多半是服务端的原因吧?reqwest/axum稳定得很,生产中使用reqwest/axum重来没出过问题。把项目源代码发到gitee.com上,大家帮你看看。

豆沙饼 is Louys 2022-01-07 17:13

我在生产上面的应用也遇到这种类似问题. 估计要去issue才行吧

1 共 3 条评论, 1 页