File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
src/main/java/com/howtoprogram/okhttp/timeout Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1818 <dependency >
1919 <groupId >com.squareup.okhttp3</groupId >
2020 <artifactId >okhttp</artifactId >
21- <version >3.4.1 </version >
21+ <version >3.4.2 </version >
2222 </dependency >
2323 <dependency >
2424 <groupId >junit</groupId >
Original file line number Diff line number Diff line change 1+ package com .howtoprogram .okhttp .timeout ;
2+
3+ import java .io .IOException ;
4+ import java .util .concurrent .TimeUnit ;
5+
6+ import okhttp3 .OkHttpClient ;
7+ import okhttp3 .Request ;
8+ import okhttp3 .Response ;
9+
10+ public class CrawlService {
11+
12+ public void doCrawl (String crawlURL ) throws IOException {
13+
14+ OkHttpClient client = new OkHttpClient .Builder ()
15+ .connectTimeout (100 , TimeUnit .SECONDS )
16+ .writeTimeout (10 , TimeUnit .SECONDS )
17+ .readTimeout (20 , TimeUnit .SECONDS ).build ();
18+
19+ // creates new request
20+ Request request = new Request .Builder ()
21+ .url (crawlURL )
22+ .build ();
23+ Response response = client .newCall (request ).execute ();
24+
25+ if (!response .isSuccessful ()) {
26+ throw new IOException ("Unexpected code " + response );
27+ }
28+
29+ }
30+
31+ }
You can’t perform that action at this time.
0 commit comments