tho*_*iha 5 rust reqwest actix-web
我有一个 actix 端点,我需要执行同步 http 客户端获取来获取一些结果,并返回一些数据。我的端点无法使用async,因此我无法使用任何.await方法。
我尝试在我的端点中使用 reqwests 阻止客户端,如下所示:
{ ...
let res = reqwest::blocking::get(&fetch_url)?
.json::<MyResp>()?;
...
Run Code Online (Sandbox Code Playgroud)
但它给了我错误:
thread 'main' panicked at 'Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks.', /.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.9/src/runtime/enter.rs:19:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
Run Code Online (Sandbox Code Playgroud)
我不知道如何让它与 actix 一起工作reqwest(它一定与 actix 有一些奇怪的冲突),但由于某种原因它与chttp.
chttp::get(&fetch_url)?.text()?;
| 归档时间: |
|
| 查看次数: |
1887 次 |
| 最近记录: |