首页 > 解决方案 > 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 --> 但它很接近并且没有得到任何解决方案。

标签: javaandroidretrofit2okhttp3android-proguard

解决方案


推荐阅读