- python 的 json.dumps([0,1,2]) 得出来的是个 str 字符串,长度为 9
- rust 应该如何处理这个呢
- 我有个接口需要 post 上传"[0,1,2]"这种模式的数据
- rust 我使用了 json!还有"[0,1,2]"还有 b"[0,1,2]"都不可以
- 但是 python 的 json.dumps 使用 requests 直接请求就可以为什么 rust 不可以呢....现在还没搞明白
1
PTLin Jun 12, 2024
先把问题描述明白,在把有问题的代码发上来,在把你疑惑的点和错误标出来
|
2
knightdf Jun 12, 2024
首先你 rust 用的什么包 post 的?看接口参数是什么类型,是 u8 还是 str
还是上代码吧 |
3
PTLin Jun 12, 2024
你要 post [0,1,2]用 reqwest 直接这样不就好了
```rust use std::error::Error; #[tokio::main] async fn main() ->Result<(),Box<dyn Error>> { let req = reqwest::Client::new() .post("http://httpbin.org/post") .body("[0,1,2]") .send() .await?; let req = req.text().await?; println!("{req}"); Ok(()) } ``` |
4
likeccpo OP 解决了,垃圾 server 服务器不识别全小写的 header,已经在 reqwest 标识了、、、
|