java - HTTP 失败:java.net.SocketException:recvfrom 失败:ECONNRESET(对等方重置连接)
问题描述
使用 pro-guard 进行改造时面临的问题
HTTP FAILED: java.net.SocketException: recvfrom failed: ECONNRESET
(Connection reset by peer)
我知道这个问题已经被问过了,但是我面临的这个错误来自其他场景......找到了与这个错误相关的链接,但我没有任何合适的解决方案。
在Android中获取“SocketException:对等方重置连接”
https://github.com/square/retrofit/issues/1027
我Retrofit
HTTP client
通过使用正文请求用于 api 调用。
@POST("users/new")
Call<User> createUser(@Body User user);
我的客户
public static OkHttpClient getClient() {
if (client == null) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
RequestInterceptor m1RequestInterceptor = new RequestInterceptor();
client = new OkHttpClient.Builder()
.connectTimeout(2, TimeUnit.MINUTES)
.readTimeout(2, TimeUnit.MINUTES)
.addInterceptor(interceptor)
.addInterceptor(m1RequestInterceptor)
.build();
}
return client;
}
亲守规则
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
问题:当我向服务器发出请求以进行单次响应时将完美运行并从服务器获得响应,但是当我一次发出多个请求(超过 5 个对服务器的请求)时HTTP FAILED: java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
注意:没有 proguard 可以正常工作,但是当我添加 proguard 时,我遇到了上述问题
我也得到了这个链接--> https://github.com/square/retrofit/issues/1027 --> 但它很接近并且没有得到任何解决方案。
解决方案
推荐阅读
- javascript - 在 Firefox 中加载伊朗地图时出错
- xcode - 检测到可能有害的通知发布率
- qt - Qt5 样式表:仅在默认设置上应用样式
- javascript - jQuery选中的限制复选框
- ios - 您如何为 swift 的有效用户名编写正则表达式?
- c# - 通过 C# 中的向上和向下箭头键导航 ListViewItem
- java - Netbeans 8.2 不创建单个项目
- android - 即使成功插入许多记录,游标也始终为空
- vba - 适用于 VBA 的 MathType 7 SDK
- node.js - 在内存中缓冲数据 - 从未调用过 Writable.final() 钩子