0

I read many posts about setConnectTimeout but I really wonder how this method could work because we cannot initialize it before openConnection() exists.

HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

urlConnection.setConnectTimeout(5000);
urlConnection.setReadTimeout(2000);

...

So what is the purpose of setConnectTimeout()?

fralbo
  • 2,534
  • 4
  • 41
  • 73
  • possible duplicate of [How to use URLConnection Timeout](http://stackoverflow.com/questions/6529733/how-to-use-urlconnection-timeout) – Michael Todd Mar 25 '15 at 16:50

1 Answers1

0

You're just opening / initializing the connection. You haven't actually called urlConnection.connect() yet. You're only initializing things like the URL, headers, setting your request method, etc.

It'll come into effect once you actually run the connection.

jlindenbaum
  • 1,891
  • 18
  • 28