nextdiscover
V2EX  ›  Android

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

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