retrofit 自定义请求参数加密 和自定义响应解密 带你走出那些坑

 首先,感谢一叶飘舟。给我灵感。

以及他分享的博文,从源码的角度来实现参数的加解密。

其次,也感谢这位这篇文章 :http://blog.csdn.net/zr940326/article/details/51549310

 技术性人员就是不喜欢多啰嗦,直接来看代码吧。

首先要了解这个东西   --------  ConverterFactory。


这是retrofit 里面一个比较重要的类,他管理着request 和response ,要想实现自己需求的请求和参数,他是两者的桥梁。

(PS:retrofit 的封装是一门艺术,这里就不多讲了,基本的配置以及结合RX来实现 的文章已经很多了,自己去好好看看)


好的,接下来我们看下 Converter工厂的源码,直接从as 贴了

public interface Converter<F, T> {
    T convert(F var1) throws IOException;

    public abstract static class Factory {
        public Factory() {
        }

        public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
            return null;
        }

        public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
            return null;
        }

        public Converter<?, String> stringConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
            return null;
        }
    }
}

三部分组成:请求 、响应、StringConverter

我们再来看看retrofit 给我提供的Converter

public final class GsonConverterFactory extends Factory {
    private final Gson gson;

    public static GsonConverterFactory create() {
        return create(new Gson());
    }

    public static GsonConverterFactory create(Gson gson) {
        return new GsonConverterFactory(gson);
    }

    private GsonConverterFactory(Gson gson) {
        if(gson == null) {
            throw new NullPointerException("gson == null");
        } else {
            this.gson = gson
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值