OkHttp拦截器

来源:互联网 发布:用c语言编写一个小游戏 编辑:程序博客网 时间:2024/05/29 23:44
一个类轻松搞定
public class ok {    OkHttpClient client = new OkHttpClient();    String run(String url) throws IOException {        Request request = new Request.Builder()                .url(url)                .build();        Response response = client.newCall(request).execute();        return response.body().string();    }    //拦截器    public interface Interceptor {        Response intercept(Chain chain) throws IOException;        interface Chain {            Request request();            Response proceed(Request request) throws IOException;            /**             * Returns the connection the request will be executed on. This is only available in the chains             * of network interceptors; for application interceptors this is always null.             */            @Nullable            Connection connection();        }    }}
原创粉丝点击