In Java, httpurlconnection can be used to request web resources.
The httpurlconnection object cannot be constructed directly. You need to use URL. openconnection () to obtain the httpurlconnection object. The sample code is as follows:
String szurl = "http://www.ee2ee.com /";network timeout
URL url = new URL (szurl );
Httpurlconnection urlcon = (httpurlconnection) URL. openconnection ();revelation online network connection timeout
Httpurlconnection is based on the HTTP protocol and is implemented through socket communication at the underlying layer. If the timeout value is not set, the program may be frozen and will not continue to be executed due to network exceptions. You can use the following two statements to set the corresponding Timeout:spark network timeout
System. setproperty ("sun.net. Client. defaulttimetimeout", timeout string in milliseconds );
System. setproperty ("sun.net. Client. defaultreadtimeout", timeout string in milliseconds );spark network timeout
Among them: sun.net. Client. defaultconnecttimeout: the timeout time for connecting to the host (unit: milliseconds)
Sun.net. Client. defaultreadtimeout: the timeout time for reading data from the host (unit: milliseconds)
For example:
System. setproperty ("sun.net. Client. defaulttimetimeout", "30000 ");sirius network timeout
System. setproperty ("sun.net. Client. defaultreadtime
In Java, httpurlconnection can be used to request web resources.
The httpurlconnection object cannot be constructed directly. You need to use URL. openconnection () to obtain the httpurlconnection object. The sample code is as follows:
String szurl = "http://www.ee2ee.com /";
URL url = new URL (szurl );
Httpurlconnection urlcon = (httpurlconnection) URL. openconnection ();
Httpurlconnection is based on the HTTP protocol and is implemented through socket communication at the underlying layer. If the timeout value is not set, the program may be frozen and will not continue to be executed due to network exceptions. You can use the following two statements to set the corresponding Timeout:
System. setproperty ("sun.net. Client. defaulttimetimeout", timeout string in milliseconds );
System. setproperty ("sun.net. Client. defaultreadtimeout", timeout string in milliseconds );
Among them: sun.net. Client. defaultconnecttimeout: the timeout time for connecting to the host (unit: milliseconds)
Sun.net. Client. defaultreadtimeout: the timeout time for reading data from the host (unit: milliseconds)
For example:
System. setproperty ("sun.net. Client. defaulttimetimeout", "30000 ");how to fix nba live mobile network timeout
System. setproperty ("sun.net. Client. defaultreadtimeout", "30000 ");
In versions earlier than JDK 1.5, only the two system attributes can be set to control network timeout. In 1.5, you can also use the following two methods of the httpurlconnection parent class urlconnection:
Setconnecttimeout: sets the host connection timeout (unit: milliseconds)
Setreadtimeout: sets the time-out for data reading from the host (unit: milliseconds)
For example:
Httpurlconnection urlcon = (httpurlconnection) URL. openconnection ();
Urlcon. setconnecttimeout (30000 );
Urlcon. setreadtimeout (30000 );
Note that, in the jdk1.4.2 environment, I found that when defaultreadtimeout is set, timeout or other network error if the network times out, httpurlconnection will automatically submit a request again, and a request call will appear, trouble ). I think this is a bug in jdk1.4.2. In jdk1.5.0, this problem has been solved and automatic resend does not exist. Out "," 30000 ");
In versions earlier than JDK 1.5, only the two system attributes can be set to control network timeout. In 1.5, you can also use the following two methods of the httpurlconnection parent class urlconnection:
Setconnecttimeout: sets the host connection timeout (unit: milliseconds)
Setreadtimeout: sets the time-out for data reading from the host (unit: milliseconds)
For example:
Httpurlconnection urlcon = (httpurlconnection) URL. openconnection ();
Urlcon. setconnecttimeout (30000 );
Urlcon. setreadtimeout (30000 );
Note that, in the jdk1.4.2 environment, I found that when defaultreadtimeout is set, if the network times out, httpurlconnection will automatically submit a request again, and a request call will appear, trouble ). I think this is a bug in jdk1.4.2. In jdk1.5.0, this problem has been solved and automatic resend does not exist.