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

将OkHttp 2.0.0与Volley集成的当前模式是什么?

最佳答案

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

  • 下载或设置okhttp-urlconnection的依赖项
  • 重写OkHttpStack以使用OkUrlFactory类:
    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);
       }
    }
  • 10-08 13:48