Setting connection timeout |
![]() ![]() ![]() |
You can use the Http#setTimeout method to define the maximum number of milliseconds to wait when establishing a connection to an HTTP server. Failure to establish a connection within the maximum time allowed will result in a HttpException.
Example
// create new HttpRequest HttpRequest request = new HttpRequest("http://www.myserver.com");
// create new Http instance Http http = new Http();
// set timeout to 5 seconds http.setTimeout(5000);
// get response HttpResponse response = http.getResponse(request); |