V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
likeccpo
V2EX  ›  Rust

[求助] rust 转义字符问题

  •  
  •   likeccpo · 6 天前 · 268 次点击
    • 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 条附言  ·  6 天前
    解决了,垃圾 server 服务器不识别全小写的 header,已经在 reqwest 标识了、、、
    4 条回复    2024-06-12 17:56:21 +08:00
    PTLin
        1
    PTLin  
       6 天前
    先把问题描述明白,在把有问题的代码发上来,在把你疑惑的点和错误标出来
    knightdf
        2
    knightdf  
       6 天前
    首先你 rust 用的什么包 post 的?看接口参数是什么类型,是 u8 还是 str
    还是上代码吧
    PTLin
        3
    PTLin  
       6 天前
    你要 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(())
    }
    ```
    likeccpo
        4
    likeccpo  
    OP
       6 天前
    解决了,垃圾 server 服务器不识别全小写的 header,已经在 reqwest 标识了、、、
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3113 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:46 · PVG 19:46 · LAX 04:46 · JFK 07:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.