OkHttpClient 请求超时问题-------以解决_realbufferedsource.indexof-程序员宅基地

技术标签: 好记性不如烂笔头  socket  

java.net.SocketTimeoutException: timeout
at okio.Okio$4.newTimeoutException(Okio.java:230)
at okio.AsyncTimeout.exit(AsyncTimeout.java:285)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:241)
at okio.RealBufferedSource.indexOf(RealBufferedSource.java:345)
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:217)
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:211)
at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:75)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
at okhttp3.RealCall.execute(RealCall.java:69)
at com.zhongan.app.mdp.core.rsasign.TestLeyue.outPatientSettlement(TestLeyue.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.net.SocketException: Socket Closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at okio.Okio$2.read(Okio.java:139)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)

... 46 more

报错如上 ↑↑

原本是
OkHttpClient client = new OkHttpClient();
更改为
OkHttpClient client = new OkHttpClient.Builder()
        .connectTimeout(500, TimeUnit.MILLISECONDS)
        .readTimeout(500, TimeUnit.MILLISECONDS)
        .build();
大功告成 !!!

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Hades__/article/details/77866378

智能推荐

java json框架_Java JSON技术框架选型与实例(转)-程序员宅基地

文章浏览阅读178次。JSONJSON英文全称为JavaScript Object Natation,采用key:value键值对的方式存贮数据,与xml格式相比,JSON是一种轻量级的数据交换格式;不要被Javascript这个单词迷惑,实际上JSON只是一种数据格式,与具体语言并无关系。JSON已被广泛应用于业界,比如目前NoSQL数据库存贮大都采用key:value存贮结构,以Mongo为例,其脚本语法甚至直接使..._java json无漏洞框架

线程池是什么?线程池(ThreadPoolExecutor)使用详解-程序员宅基地

文章浏览阅读5k次,点赞5次,收藏20次。先看ThreadPoolExecutor 的构造方法重点理解一下这几个参数含义:先情景带入一下,把线程池当作公司,一类正式员工;一类实习生;1.corePoolSize:核心线程数,相当于正式员工2.maxinumPoolSize:最大线程数,相当于正式员工+实习生3.long keepAliveTime:实习生线程保持存活的时间当任务比较少的时候,整体比较空闲,实习生不是立即被辞退的,表示实习生最大的存活时间4.TimeUnit unit:单位,秒,分钟,毫秒5._线程池

ORM框架_java spring boost orm linq-程序员宅基地

文章浏览阅读283次。对象关系映射(ORM)提供了概念性的、易于理解的模型化数据的方法。ORM方法论基于三个核心原则: 简单:以最基本的形式建模数据。 传达性:数据库结构被任何人都能理解的语言文档化。 精确性:基于数据模型创建正确标准化了的结构。 典型地,建模者通过收集来自那些熟悉应用程序但不熟练的数据建模者的人的信息开发信息模型。建模者必须能够用非技术企业专家可以理解的术语在概念层次上与数据结构进行通讯。建模者也必须_java spring boost orm linq

uni-app 表单验证_uni-forms-item-程序员宅基地

文章浏览阅读5.3k次。uni 表单验证本文只用做记录及学习使用<uni-forms modelValue="formData" ref="setPwdForm" :rules="rules"> <uni-forms-item label="手机号:"> <uni-easyinput type="number" v-model="formData.phone" maxlength="11" placeholder="请输入11位电话号码" /> </uni-forms-item_uni-forms-item

[UE4] 自定义资源类型(Asset)创建与使用_ue的asset只包含数据-程序员宅基地

文章浏览阅读2.4k次,点赞2次,收藏3次。内容自学自B站AV244462117,P8~15该文仅为自学记录,并非教程,可能存在谬误系统环境:WIN10, UE4(引擎版本4.27.1),Visual Studio 2022 Community1. 自定义资源类型(Asset)的创建1.1 自定义插件创建2. 增加外界拖入导入功能..._ue的asset只包含数据

web前端网页制作课作业:校园科技节活动网站 (纯HTML+CSS布局制作)_科技项目首页样式设计-程序员宅基地

文章浏览阅读812次,点赞18次,收藏22次。学生HTML静态网页基础水平制作,页面排版干净简洁。使用HTML+CSS页面布局设计,web大学生网页设计作业源码,这是一个不错的旅游网页制作,画面精明,排版整洁,内容丰富,主题鲜明,非常适合初学者学习使用, 这个实例比较全面,有助于同学的学习,本文将介绍如何通过从头开始设计个人网站并将其转换为代码的过程来实践设计。 【作者主页——获取更多优质源码】 【学习资料/简历模板/面试资料/ 网站设计与制作】 【web前端期末大作业——毕设项目精品实战案例】文章目录_科技项目首页样式设计

随便推点

Win10 SSH连接VirtualBox虚拟机中的Ubuntu的方法_powershell用ssh远程连接virtualbox虚拟机桥接模式-程序员宅基地

文章浏览阅读675次。在VirtualBox中设置网络为桥接。在Ubuntu虚拟机中打开终端,执行下面的命令:sudo apt-get install ssh在Win10中打开powershell,输入下面的命令就可以连接上虚拟机中的ubuntu了:ssh user_name@ip_of_your_ubuntu_vm..._powershell用ssh远程连接virtualbox虚拟机桥接模式

LoadRunner_Transaction_loadrunner的analysis的transaction的response time包含was-程序员宅基地

文章浏览阅读583次。(1)定义 事务是这样一个点,我们为了衡量某个操作的性能,需要在操作开始和结束的位置,插入一个范围,这样就定义了一个Transaction(事务)。(2)原因 从性能测试的角度出发,我们需要知道不同的操作所花费的时间,这样我们就可以衡量不同的操作对被测系统所造成的影响,那么我们如何知道不同的操作系统所花费的时间,这就用到了事务,我们在操作之前插入一个事务开始标志,在..._loadrunner的analysis的transaction的response time包含wasted time不

TensorFlow和深度学习-无需博士学位(TensorFlow and deep learning without a PhD)_five_layers_sigmoid.py源码-程序员宅基地

文章浏览阅读1.3k次。1. 概述原文地址:TensorFlow and deep learning,without a PhDLearn TensorFlow and deep learning, without a Ph.D. B站视频地址:https://www.bilibili.com/video/av8284296https://www.bilibili.com/video/av16339227不要太多地关注..._five_layers_sigmoid.py源码

mysql list拼接_mysql拼接多条字段-程序员宅基地

文章浏览阅读582次。未合并情况SELECTa.id,b.nameAS "role"FROMsys_user aINNER JOIN sys_user_role c ON a.id=c.user_idINNER JOIN sys_role b ON b.id =c.role_idWHEREa.del_flag=0ANDb.del_flag=0结果id                  role1            ..._mysql 拼接list

python渐变色代码_python生成渐变色-程序员宅基地

文章浏览阅读3.5k次。使用RGB颜色,两种颜色间设置一定的步长,就能生成想要的渐变色import seaborn as snsimport matplotlib.pyplot as plt# RGB格式颜色转换为16进制颜色格式def RGB_to_Hex(rgb):RGB = rgb.split(',') # 将RGB格式划分开来color = '#'for i in RGB:num = int(i)# 将R、G、..._python渐变色代码