Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.
If the connect
method is called when the connection has already been opened (indicated by the connected
field having the value true
), the call is ignored.
URLConnection objects go through two phases: first they are created, then they are connected. After being created, and before being connected, various options can be specified (e.g., doInput and UseCaches). After connecting, it is an error to try to set them. Operations that depend on being connected, like getContentLength, will implicitly perform the connection, if necessary.
@throws SocketTimeoutException if the timeout expires beforethe connection can be established
@exception IOException if an I/O error occurs while opening theconnection.
@see java.net.URLConnection#connected
@see #getConnectTimeout()
@see #setConnectTimeout(int)