android - 改造 2 使请求编译但抛出 sockettimeoutexception
问题描述
我在这里遇到了最奇怪的问题。我正在使用改造来发出请求,但起初我收到套接字超时异常,我认为这是后端问题,但它正在处理邮递员。然后当我们检查后端日志时,我们意识到请求将被编译并提供 200 个代码,但我没有得到任何响应!!!!!!
这是我的代码
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
这是我的代码初始化改造
private static Retrofit cRetrofit = null;
private static Retrofit retrofit = null;
private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
public static final int CACHE_EX_TIME = 60;
public static Retrofit getClient(String baseUrl) {
Gson gson = new GsonBuilder()
.setLenient()
.create();
httpClient.connectTimeout(15, TimeUnit.SECONDS);
httpClient.readTimeout(15, TimeUnit.SECONDS);
httpClient.writeTimeout(15, TimeUnit.SECONDS);
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(httpClient.build())
.build();
}
return retrofit;
}
解决方案
推荐阅读
- visual-studio-code - 在 Visual Studio Code ( VS Code ) 中,有没有办法在同一个文档中添加不同颜色的注释?(即针对不同的主题|人)
- r - 错误:包“TStools”的延迟加载失败
- reactjs - Heroku:为什么在 React 应用程序部署后我会收到 H10 错误?
- python - 如何实现 python 代码作为 Azure 函数工作?
- java - 使用多个 JPanel 类时如何在 JFrame 中打开另一个 JPanel
- node.js - Stripe Node.js - 如何在多个受益人(关联账户)之间拆分付款?
- bash - 如果在第二列中有使用 bash 的浮点数,则删除整行
- three.js - Threejs用多个对象更新glb上的单一材料
- r - 创建事件变量的时间和时间
- methods - 我如何为这个 Rust 特征使用相同的默认实现