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)
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With