okhttp3.internal.http2.StreamResetException: stream was reset: INTERNAL_ERROR
来源:互联网 发布:js获取当前时间字符串 编辑:程序博客网 时间:2024/06/04 01:13
BUG:
okhttp3.internal.http2.StreamResetException: stream was reset: INTERNAL_ERROR
原因是协议错误导致的,在实例化 okhttpclient 的时候用以下方法:
okHttpClient = httpBuilder .protocols(Collections.singletonList(Protocol.HTTP_1_1)) .build();
完整代码贴下:
private static OkHttpClient okHttpClient = null; private static final int DEFAULT_TIMEOUT = 30;// 20 private static Context mContext; public static OkHttpClient getOkHttpSingletonInstance() { if (okHttpClient == null) { synchronized (OkHttpClient.class) { if (okHttpClient == null) { okHttpClient = new OkHttpClient(); //设置合理的超时 OkHttpClient.Builder httpBuilder = new OkHttpClient.Builder() .readTimeout(3, TimeUnit.SECONDS) .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS) //设置连接超时 30秒 .writeTimeout(3, TimeUnit.MINUTES) .addInterceptor(new LoggingInterceptor())//添加请求拦截 .retryOnConnectionFailure(true); //如果不是在正式包,添加拦截 打印响应json if (BuildConfig.DEBUG) { HttpLoggingInterceptor logging = new HttpLoggingInterceptor( new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { if (TextUtils.isEmpty(message)) return; String s = message.substring(0, 1); //如果收到响应是json才打印 if ("{".equals(s) || "[".equals(s)) { LogUtils.i("收到响应: " + message); } } }); logging.setLevel(HttpLoggingInterceptor.Level.BODY); httpBuilder.addInterceptor(logging); } okHttpClient = httpBuilder .protocols(Collections.singletonList(Protocol.HTTP_1_1)) .build(); } } } return okHttpClient; }
阅读全文
0 0
- okhttp3.internal.http2.StreamResetException: stream was reset: INTERNAL_ERROR
- com.sun.java_cup.internal.internal_error
- Android OkHttp3使用http2问题记录
- unexpected end of stream on okhttp3.
- http2
- HTTP2
- HTTP2
- http2
- http2
- There was an internal error.
- SSH连接错误:connection was reset
- -2 internal error : deflate stream corrupt
- unexpected end of stream on okhttp3.Address 错误原因
- java.io.IOException: unexpected end of stream on okhttp3.Address
- There was an internal API error.
- There was an internal API error.
- There was an internal API error.
- There was an internal Api failed
- 文章标题
- 文章标题
- 视觉学习零 ——环境搭建
- 文章标题
- Webpack工程化解决方案easywebpack
- okhttp3.internal.http2.StreamResetException: stream was reset: INTERNAL_ERROR
- 我对rxjava的理解
- KV存储的对比
- Linux出现Bash . configure permission denied错误
- android TextView selector点击样式改变
- java 统计文本中出现概率最高的10个字符串
- Java 网络编程
- 日常运维(四):iptables filter表案例 iptables nat表应用
- 【51Nod