拦截器+post+get
来源:互联网 发布:php贴吧盖楼源代码 编辑:程序博客网 时间:2024/06/11 22:44
package com.example.bwei.myinterceptors;import java.io.IOException;import java.net.URL;import okhttp3.FormBody;import okhttp3.Interceptor;import okhttp3.Request;import okhttp3.RequestBody;import okhttp3.Response;/** * Created by QinQinBaoBei on 2017/12/7. */public class MyInterceptors implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { //post请求 Request request = chain.request(); FormBody.Builder builder= new FormBody.Builder(); FormBody body = (FormBody) request.body(); //获取原来的请求参数 for(int i=0;i<body.size();i++){ String name = body.name(i); String value = body.value(i); builder.add(name,value); } //添加新的请求参数 builder.add("source","android"); FormBody newbody = builder.build(); //生成一个有公共参数的新request Request request1 = request.newBuilder().post(newbody).build(); Response response = chain.proceed(request1); return response; } /* public void get(){ //get请求 Request request = chain.request(); String s = request.url().url().toString(); String url = s+"&source=android"; Request request1 = request.newBuilder().url(url).build(); Response response = chain.proceed(request1); }*/}
阅读全文
0 0
- 拦截器+post+get
- 自定义拦截器GET请求POST请求
- get方法/post方法应用拦截器
- okhttp自定义拦截器,封装公共参数,get或post请求不同的拦截器
- OKHttp使用拦截器(Interceptor)POST与GET方法,统一封装传公共参数
- 【Angular】angular-HttpClient 与服务器通讯 Get Post Put Delete Http 拦截器 请求讲解
- jfinal框架中控制请求访问方式get or post 的拦截器写法
- Android如何拦截WebView之中的Post或者Get请求
- 自定义拦截器 post请求
- 自定义拦截器(post)
- post get
- Get, Post
- GET/POST
- get/post
- get post
- get post
- get post
- post get
- Scrapy添加随机ip
- Android RecyclerView一键快速切换布局样式
- java并发编程实践(3)
- 【洛谷】3807 【模板】卢卡斯定理
- pygame颜色设置
- 拦截器+post+get
- Java序谈之代码块和继承知识
- 学习日志2017.12.07
- c++关于cin作为while条件的问题
- 学习笔记-盒子模型应用1
- js原生实现高性能懒加载(分步解析)
- DispatcherServlet详解
- bzoj3196: Tyvj 1730 二逼平衡树
- 2017年12月7日训练总结