【发布时间】:2017-02-19 17:04:15
【问题描述】:
我为我的 Android 应用程序使用了 Retrofit 库。我需要将连接超时设置为 120 秒。我能怎么做 ?
版本:
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
OperatingApiClient:
public class OperatingApiClient {
public static final String BASE_URL = "http://172.16.2.39/";
private static Retrofit retrofit = null;
public static Retrofit getClient() {
if (retrofit==null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
TargetFileApi接口:
public interface TargetFileApiInterface {
@GET("NNGOperating/GetTargetFileList")
Call<TargetFileApiResponse> getTargetFileList(@Query("api_key")
String apiKey);
}
TargetFileApiResponse:
public class TargetFileApiResponse {
@SerializedName("TargetFileList")
private List<TargetFile> targetfileslist;
public TargetFileApiResponse(List<TargetFile> targetfileslist) {
this.targetfileslist = targetfileslist;
}
public List<TargetFile> getTargetfileslist() {
return targetfileslist;
}
public void setTargetfileslist(List<TargetFile> targetfileslist) {
this.targetfileslist = targetfileslist;
}
}
【问题讨论】:
标签: android retrofit retrofit2