System.Net.WebException:操作已超时 [英] System.Net.WebException: The operation has timed out

查看:93
本文介绍了System.Net.WebException:操作已超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大问题:我需要一次发送200个对象,并避免超时.

I have a big problem: I need to send 200 objects at once and avoid timeouts.

while (true)
{

    NameValueCollection data = new NameValueCollection();
    data.Add("mode", nat);

    using (var client = new WebClient())
    {
        byte[] response = client.UploadValues(serverA, data);
        responseData = Encoding.ASCII.GetString(response);

        string[] split = Javab.Split(new[] { '!' },  StringSplitOptions.RemoveEmptyEntries);
        string command = split[0];
        string server = split[1];
        string requestCountStr = split[2];

        switch (command)
        {
            case "check":
                int requestCount = Convert.ToInt32(requestCountStr);

                for (int i = 0; i < requestCount; i++)
                {
                    Uri myUri = new Uri(server);
                    WebRequest request = WebRequest.Create(myUri);
                    request.Timeout = 200000;
                    WebResponse myWebResponse = request.GetResponse();
                }
                break;
        }
    }    
}

这会产生错误:

Unhandled Exception: System.Net.WebException: The operation has timed out  
at System.Net.HttpWebRequest.GetResponse()  
at vir_fu.Program.Main(String[] args)

requestCount循环在我的基本代码之外工作正常,但是当我将其添加到项目中时,出现此错误.我尝试设置request.Timeout = 200;,但没有帮助.

The requestCount loop works fine outside my base code but when I add it to my project I get this error. I have tried setting request.Timeout = 200; but it didn't help.

推荐答案

它表示的意思.该操作花了太长时间才能完成.

It means what it says. The operation took too long to complete.

顺便说一句,请查看 WebRequest.Timeout ,您会看到 您已将超时时间设置为1/5秒 .

BTW, look at WebRequest.Timeout and you'll see that you've set your timeout for 1/5 second.

这篇关于System.Net.WebException:操作已超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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