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

dio.get 请求使用二进制参数的问题

  •  
  •   LeGendAI ·
    LeGend-AI · 2020-04-26 16:43:50 +08:00 · 1126 次点击
    这是一个创建于 1461 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近想用 flutter 写一个 bt 下载器 http://www.bittorrent.org/beps/bep_0003.html 参考文档里 Tracker GET requests 的说明,info_hash 需要传递的是 160bit 的数据。

    我是使用

    var info = String.fromCharCodes(hex.decode(info_hash));
    var param = {
      'info_hash': info,
      ...
    }
    
    var response = await dio.get(tracker, queryParameters: param);
    

    的方式传递参数(info_hash 是对应的 hex 字符串)。

    但是 tracker 返回d14:failure reason25:info_hash is not 20 bytese错误。

    我发现可能是因为默认使用 utf8 编码,在对 queryParameter 做 urlencode 的时候添加了额外的编码信息(%C2)。

    有没有朋友有方法在 get 请求参数里设置二进制数据呢?

    附上我测试的数据:

    tracker: http://nyaa.tracker.wf:7777/announce

    info_hash: 982e7c13ca3effc64c9d72fc77088d9a807a56ac

    length: 10079407917

    1 条回复    2020-12-10 15:53:24 +08:00
    YYSWDD
        1
    YYSWDD  
       2020-12-10 15:53:24 +08:00
    你好,你解决了吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4778 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 09:56 · PVG 17:56 · LAX 02:56 · JFK 05:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.