问题标签 [reqwest]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
6209 浏览

rust - 无法调用返回结果的函数:发现不透明类型 impl std::future::Future

我无法从Result. 每个教程只展示如何使用一个结果,而不是如何从它返回一个值。

我收到以下错误:

0 投票
1 回答
523 浏览

url - Rust URL 删除特定的 GET 参数

我有这个 URL 作为String: "http://blah.com/a/b?a=1&b=2"

如何b使用 Rust 删除或替换 GET 参数或完全剥离参数?

rust-url 包的ParseOptions似乎没有给我任何东西。

我是否仅限于使用字符串方法来查找/替换?

0 投票
1 回答
3676 浏览

rust - Rust 下载并保存 ZIP 文件

我正在尝试下载并保存一个 Zip 文件。似乎下载正常,但保存出错。如果我尝试解压缩文件,我会收到以下错误:

这是我正在使用的代码:

货物.toml

src/main.rs

任何人都可以帮助我吗?

0 投票
1 回答
546 浏览

post - 如何使用 Hyper 或 Reqwest 获取原始 HttpResponse?

有没有办法在做一个之后得到实际的/原始的/原始的 http 响应reqwest::get("https://httpbin.org/ip").send().await?

或来自超:client.get("https://httpbin.org/ip".parse()?).await?

我需要与邮递员返回的结果类似的结果:

不知何故,reqwest 将响应组织得很好。进入version(), status(),headers()

我特别提到 reqwest 和/或 hyper 的原因是因为它们在代码中被广泛使用。在我们尝试另一个 crate/lib 之前,我希望我仍然可以使用它们。

0 投票
1 回答
146 浏览

rust - Collapse Rust Matching

I am new to rust, and am missing the if let and guard let notation in Swift.

I have the following code block:

In swift I would have written something like:

Am I missing some shorthand notation?

I'm trying to make use of the ability to return from anywhere with return to short circuit some of the execution, but it's still much more verbose than I am familiar with.


EDIT:

I can collapse some of the rust with the match + clause syntax as below:

That is much better than the original.

If let also works, but the problem with if let here is that I'm looking at the failure path here. I do not want to nest in on the happy path.

0 投票
1 回答
484 浏览

multithreading - Rust 多线程 HTTP 请求,从响应中获取所有数据?

所以我有以下代码将多线程请求发送到域列表。到目前为止,我能够从响应中获取单个数据,例如字节、url 或状态码等,但不能将它们全部放在一起。我想将所有这些值存储到向量中,以便可以将其写入文件。我知道这可能是一个超级愚蠢的问题,但我已经研究了好几天,无法弄清楚。任何帮助表示赞赏!

0 投票
1 回答
1699 浏览

rust - reqwest::Error { 种类:解码,来源:错误(“预期值”,行:1,列:1)}'

创建此 POST 请求时出现以下错误。我是 RUST 的新手。

而不是serde_json::Value我什至尝试HashMap<String, String>过同样的问题。如果你能告诉我我的标题是否错误,或者我如何追踪它是否真的是网络 reqwest 问题?

这是我期待的实际反应。Session我试图将serde_json::Value 替换为 Session仍然没有影响错误仍然存​​在。

我正在使用 Popos 20.04 和 Rust 1.45.2

这只会给我以下错误: reqwest::Error { kind: Decode, source: Error("expected value", line: 1, column: 1) }'

谢谢你。

0 投票
1 回答
237 浏览

arrays - 为什么使用 reqwest 下载的 PNG 图像的字节数与使用 Python 下载的字节数不同?

我正在尝试使用 reqwest 库来下载 PNG 文件,但是当我下载它时,我看到一个奇怪的行为尊重其他编程语言,例如:Python。

例如:

如果我将结果打印为字节数组(println!("{:?}", content.text().await?.as_bytes());

但是,使用 Python 请求的结果是:

在 Rust 版本中,我看到了很多191, 189. 这个序列在整个数组中重复了很多次,但在 Python 中根本不会出现。

我在 Rust 中做错了什么?

0 投票
1 回答
821 浏览

rust - 在 rust 中使用 reqwest 获取响应标头值

在过去的几天里,我主要是在试验 reqwest 模块,看看我能完成什么,但我遇到了一个我无法解决的问题。我尝试在执行发布请求后检索响应标头值。我尝试的代码是

此代码似乎返回此错误

0 投票
1 回答
1801 浏览

json - 如何在 Rust 中使用 reqwest 反序列化任意 json 结构?

我对 rust 完全陌生,我正在尝试找出如何从 URL 端点加载反序列化任意 JSON 结构。

reqwest README 中的相应示例如下所示:

所以在这个例子中,目标结构——即一个以字符串为键、字符串为值的HashMap对象——显然是已知的。

但是,如果我不知道在请求端点上接收到的结构是什么样的呢?