本文介绍了如何实现机器人与排球2.0 OkHttp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这OkHttpStack不再在OkHttp2.0支持:https://gist.github.com/JakeWharton/5616899

This OkHttpStack is no longer supported in OkHttp2.0:https://gist.github.com/JakeWharton/5616899

什么是目前的格局,整合OkHttp 2.0.0与排球?

What is the current pattern to integrate OkHttp 2.0.0 with Volley?

推荐答案

您必须使用okhttp-URLConnection的模块,实现了java.net.HttpURLConnection中的API,因此:

You must use okhttp-urlconnection module that implements the java.net.HttpURLConnection API, so:

  • 下载或设置一个依赖关系,<一个href="http://search.maven.org/remotecontent?filepath=com/squareup/okhttp/okhttp-urlconnection/2.0.0/okhttp-urlconnection-2.0.0.jar">okhttp-urlconnection

重写你的OkHttpStack要利用OkUrlFactory类:

Rewrite your OkHttpStack to make use of the OkUrlFactory class:

public class OkHttpStack extends HurlStack {
   private final OkUrlFactory okUrlFactory;
   public OkHttpStack() {
       this(new OkUrlFactory(new OkHttpClient())); 
   }
   public OkHttpStack(OkUrlFactory okUrlFactory) {
       if (okUrlFactory == null) {
           throw new NullPointerException("Client must not be null.");
       }
       this.okUrlFactory = okUrlFactory;
   }
   @Override
   protected HttpURLConnection createConnection(URL url) throws IOException {
       return okUrlFactory.open(url);
   }
}

这篇关于如何实现机器人与排球2.0 OkHttp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 12:26