Intro OKHttp Parameter CallTimeOut
Intro OKHttp Parameter CallTimeOut
這篇介紹OKHttp Parameter CallTimeOut.
官方說明:
Sets the default timeout for complete calls.
A value of 0 means no timeout, otherwise values must be
between 1 and Integer.MAX_VALUE when converted to milliseconds.
The call timeout spans the entire call: resolving DNS, connecting,
writing the request body, server processing, and reading the response body.
If the call requires redirects or retries all must complete within one timeout period.
The default value is 0 which imposes no timeout.
使用情境 & 解決方法:
一般在使用OKHttp時,經常會設定connectionTimeout和readTimeout及writeTimeout。
這次碰到當對方回應,”java.io.IOException: unexpected end of stream on {對方domain}”
代表有可能被對方CDN誤判成有問題的domain,故意不斷線且不會受到connectionTimeout、
readTimeout、writeTimeout條件造成timeout。
所以必須設定callTimeout Parameter來防止HTTP request沒有timeout而一直佔用執行緒問題。