{"id":8047,"date":"2015-11-22T03:01:05","date_gmt":"2015-11-22T03:01:05","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/22\/how-to-set-connection-timeout-with-okhttp-open-source-projects-square-okhttp\/"},"modified":"2022-08-30T15:03:03","modified_gmt":"2022-08-30T15:03:03","slug":"how-to-set-connection-timeout-with-okhttp-open-source-projects-square-okhttp","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/22\/how-to-set-connection-timeout-with-okhttp-open-source-projects-square-okhttp\/","title":{"rendered":"How to set connection timeout with OkHttp-open source projects square\/okhttp"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/284abbc6762a977f1d2b82d9d8280cde?s=128&amp;d=identicon&amp;r=PG\" \/> <strong>Miguel Lavigne<\/strong><\/p>\n<p>You simply have to do this<\/p>\n<pre><code>   OkHttpClient client = new OkHttpClient();\n   client.setConnectTimeout(15, TimeUnit.SECONDS); \/\/ connect timeout\n   client.setReadTimeout(15, TimeUnit.SECONDS);    \/\/ socket timeout\n\n   Request request = new Request.Builder().url(url).build();\n   Response response = client.newCall(request).execute();\n<\/code><\/pre>\n<p>Be aware that value set in <code>setReadTimeout<\/code> is the one used in <code>setSoTimeout<\/code> on the <code>Socket<\/code> internally in the <code>OkHttp<\/code> <code>Connection<\/code> class.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Miguel Lavigne You simply have to do this OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(15, TimeUnit.SECONDS); \/\/ connect timeout client.setReadTimeout(15, TimeUnit.SECONDS); \/\/ socket timeout Request request = new Request.Builder().url(url).build(); Response response = client.newCall(request).execute(); Be aware that value set in setReadTimeout is the one used in setSoTimeout on the Socket internally in the OkHttp Connection class.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8047","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=8047"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8047\/revisions"}],"predecessor-version":[{"id":8664,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8047\/revisions\/8664"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}