Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the time limit for webClient.UploadData()?

I am using WebClient.UploadData() to do a post on a Java server. How can I extend the time limit? (It times out every time I am trying to do some debugging)

like image 778
Grzenio Avatar asked Aug 06 '09 09:08

Grzenio


People also ask

What is WebClient default timeout?

java example code the WebClient build using the default builder without any specific configuration. Hence it falls back to the default connect and read timeout, which is 30 seconds each. Modern applications do not wait for 30 seconds for anything.


1 Answers

The WebClient doesn't have a timeout property, however it is possible to inherit from the WebClient to give access to Timeout on the internal WebRequest used:

 public class WebClientEx : WebClient  {      public int Timeout {get; set;}       protected override WebRequest GetWebRequest(Uri address)      {         var request = base.GetWebRequest(address);         request.Timeout = Timeout;         return request;      }  } 

Usage:

 var myClient = new WebClientEx();  myClient.Timeout = 900000 // Daft timeout period  myClient.UploadData(myUri, myData); 
like image 127
AnthonyWJones Avatar answered Oct 14 '22 13:10

AnthonyWJones