我从杰克逊·成加莱先生的暗示中得到了解决方案。
创建一个Okhttp请求拦截器
private static class PicassoInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); Map<String, String> map = new HashMap<String, String>(); map.put("session_id", session_id); map.put("image", image); String requestJsonBody = new Gson().toJson(map); RequestBody body = RequestBody.create(JSON, requestStringBody); final Request original = chain.request(); final Request.Builder requestBuilder = original.newBuilder() .url(url) .post(body); return chain.proceed(requestBuilder.build()); }}
创建一个Okhttp客户端,添加此拦截器
OkHttpClient okHttpClient = new OkHttpClient();okHttpClient.interceptors().add(new PicassoInterceptor());
使用此okhttp客户端创建Dowloader
OkHttpDownloader = downloader = new OkHttpDownloader(okHttpClient)
使用此下载器构建毕加索
Picasso picasso = new Picasso.Builder(context).downloader(downloader ).build();
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)