OkHttpStack已不被OkHttp2.0支持: https://gist.github.com/JakeWharton/5616899
目前将OkHttp 2.0.0与Volley集成的模式是什么?
OkHttpStack已不被OkHttp2.0支持: 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);
}
}
compile 'com.squareup.okhttp:okhttp:2.0.0' compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0' compile 'com.squareup.okio:okio:1.0.1'
- JohnRockimport com.android.volley.toolbox.HurlStack;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.OkUrlFactory;
/**
* An {@link com.android.volley.toolbox.HttpStack HttpStack} implementation
* which uses OkHttp as its transport.
*/
public class OkHttpStack extends HurlStack {
private final OkUrlFactory mFactory;
public OkHttpStack() {
this(new OkHttpClient());
}
public OkHttpStack(OkHttpClient client) {
if (client == null) {
throw new NullPointerException("Client must not be null.");
}
mFactory = new OkUrlFactory(client);
}
}
HttpStack
的OkHttp 2.0版本。 - CommonsWare