拦截器,请求头

public class Logger implements Interceptor{  
    @Override  
    public Response intercept(Chain chain) throws IOException {  
        Request original = chain.request();  
        HttpUrl url=original.url().newBuilder()  
                //需要添加的公共参数,以键值对形式添加
                .addQueryParameter("source","android")  
                .build();  
        //添加请求头  
        Request request = original.newBuilder()  
                .url(url)  
                .build();  
        return chain.proceed(request);  
    }  
} 
public class Logger2 implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder builder = chain.request().newBuilder();
        Request requst = builder
                .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .addHeader("Accept-Encoding", "gzip, deflate")
                .addHeader("Connection", "keep-alive")
                .addHeader("Accept", "*/*")
                .addHeader("Cookie", "add cookies here")
                .build();
        return chain.proceed(requst);
    }
}

你可能感兴趣的:(拦截器,请求头)