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

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.