小编dur*_*roy的帖子

如何在Android的Retrofit库中设置连接超时?

我已经为我的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'
Run Code Online (Sandbox Code Playgroud)

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;
    }
    }
Run Code Online (Sandbox Code Playgroud)

TargetFileApiInterface:

public interface TargetFileApiInterface {
@GET("NNGOperating/GetTargetFileList")
Call<TargetFileApiResponse> getTargetFileList(@Query("api_key") 
String apiKey);

}
Run Code Online (Sandbox Code Playgroud)

TargetFileApiResponse:

    public class TargetFileApiResponse {
    @SerializedName("TargetFileList")
    private List<TargetFile> targetfileslist;

    public TargetFileApiResponse(List<TargetFile> targetfileslist) {
        this.targetfileslist = targetfileslist;
    }

    public List<TargetFile> getTargetfileslist() …
Run Code Online (Sandbox Code Playgroud)

android retrofit retrofit2

2
推荐指数
1
解决办法
4517
查看次数

标签 统计

android ×1

retrofit ×1

retrofit2 ×1