nextdiscover
V2EX  ›  Android

使用 Retrofit+OkHttp,在数据发出去之前,怎样获取获取 @Field 所有参数进行签名,然后再把 sign 签名加入到请求参数里发出去完成请求

  •  
  •   nextdiscover · Sep 16, 2018 · 14052 views
    This topic created in 2796 days ago, the information mentioned may be changed or developed.
    13 replies    2018-12-19 15:26:52 +08:00
    zhchyu999
        1
    zhchyu999  
       Sep 16, 2018 via Android
    okhttp 有个拦截器
    saximoer
        2
    saximoer  
       Sep 16, 2018
    ohhttp 有一个 Interceptor 接口
    实现这个接口就 实现了拦截器的功能
    然后记得把这个拦截器加入 okhttp 的声明中就可以了
    hongch
        3
    hongch  
       Sep 16, 2018 via iPhone
    intercept 可以看一下 okhttp 源码 interceptchain 允许加入两个 intercept 分别是请求前和请求后
    nextdiscover
        4
    nextdiscover  
    OP
       Sep 17, 2018 via iPhone
    @zhchyu999 我试过了,拦截器拿到的参数只能是拦截器设置之前的参数,在 @filed 属性加入的参数拿不到
    nextdiscover
        5
    nextdiscover  
    OP
       Sep 17, 2018 via iPhone
    @saximoer 我试过了,拦截器拿到的参数只能是拦截器设置之前的参数,在 @filed 属性加入的参数拿不到
    nextdiscover
        6
    nextdiscover  
    OP
       Sep 17, 2018 via iPhone
    @hongch 我试过了,拦截器拿到的参数只能是拦截器设置之前的参数,在 @filed 属性加入的参数拿不到
    saximoer
        7
    saximoer  
       Sep 17, 2018
    wsxyeah
        8
    wsxyeah  
       Sep 17, 2018 via iPhone
    interceptor 里肯定不能直接拿到 retrofit 里的 field 啊,只能拿到 request body,可以从 request body 里取出字段再操作
    nextdiscover
        9
    nextdiscover  
    OP
       Sep 17, 2018 via iPhone
    @wsxyeah 嗯嗯,今天试试,谢谢
    nextdiscover
        10
    nextdiscover  
    OP
       Sep 17, 2018 via iPhone
    @saximoer 谢谢,我去看看
    hongch
        11
    hongch  
       Sep 17, 2018
    - - @nextdiscover 当然是拿 requestbody 如果是 get 请求就从 url 里拿
    zhchyu999
        12
    zhchyu999  
       Sep 17, 2018
    印象中好像是改不了,得 new 一个新的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5847 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 01:52 · PVG 09:52 · LAX 18:52 · JFK 21:52
    ♥ Do have faith in what you're doing.