我无法为Retrofit设置超时。以下代码在Picasso上无法正常工作。我得到了一个空白屏幕,数据和图像没有加载。如何在Gradle中修复它:
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
代码:
final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setReadTimeout(60, TimeUnit.SECONDS);
okHttpClient.setConnectTimeout(60, TimeUnit.SECONDS);
RestAdapter restAdapter = new RestAdapter.Builder()
.setClient(new OkClient(okHttpClient))
.setEndpoint(URL).build();
myapi myapi_rest = restAdapter.create(myapi.class);
myapi_rest.my_call(
sno,
new Callback<Response>() {
@Override
public void success(Response result, Response response) {
}
@Override
public void failure(RetrofitError error) {
// Log.i("Failure", "Error"+error.getMessage());
}
});
Gradle:
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile "com.squareup.okhttp:okhttp:1.6.0"
compile "com.squareup.okhttp:okhttp-urlconnection:1.6.0"
okhttp
版本。为什么?顺便说一下,您必须在OkHttpClient
中设置超时时间。 - EpicPandaForce