Create a request client locally using Okhttpclient, and debug the API interface with the error described in the presentation, first post the full error code
Exception in thread "main"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.***.***api.*** (***api.java:20) at COM.***.***Api.main (***api.java:26)
caused By:java.net.SocketTimeoutException:Read timed out at
Java.net.SocketInputStream.socketRead0 (Native Method)
At Java.net.SocketInputStream.socketRead (Socketinputstream.java:116)
At Java.net.SocketInputStream.read (Socketinputstream.java:171)
At Java.net.SocketInputStream.read (Socketinputstream.java:141)
At Okio. okio$2.read (okio.java:139) at Okio. asynctimeout$2.read (asynctimeout.java:237)
... More
The problem is that the API has been processed for a long time, and the Okhttpclient client I created didn't give enough time to take care of it, so I needed to set a longer connection and read time to 50 seconds to pass. The code looks like this:
New Okhttpclient (). Newbuilder (). ConnectTimeout (50000, Timeunit.milliseconds) . ReadTimeout (50000, Timeunit.milliseconds) . Build ();
Online has said through the following code to set the time-out period, but did not find the method of the set, have informed the small partner informed it.
New okhttpclient (); Client.setconnecttimeout (// Connect Timeoutclient.setreadtimeout (30, Timeunit.seconds); // Socket Timeout
When making API calls in Java, the "Exception in Thread" main "Java.net.SocketTimeoutException:timeout" appears, "caused by: Java.net.SocketTimeoutException:Read timed out "error