我怎样才能改变时间限制webClient.UploadData()? [英] How can I change the time limit for webClient.UploadData()?

查看:481
本文介绍了我怎样才能改变时间限制webClient.UploadData()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 WebClient.UploadData()到Java服务器上做一个职位。如何延长时间限制? (每次我试图做一些调试时间超时)

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)

推荐答案

没有超时属性的Web客户端,但它可以从Web客户端继承授予访问超时所使用的内部的WebRequest:

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;
     }
 }

用法:

 var myClient = new WebClientEx();
 myClient.Timeout = 900000 // Daft timeout period
 myClient.UploadData(myUri, myData);

这篇关于我怎样才能改变时间限制webClient.UploadData()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆