急!求助!使用HttpWebRequest类发送大量数据时,发送时间巨长,请问有人遇到过么
我使用HttpWebRequest类发送大量数据到服务器,但是有时写数据的时间都非常长,其实数据也就10几k,不知是什么原因。
我的代码如下:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
UTF8Encoding encoding = new UTF8Encoding();
Byte[] fbs = encoding.GetBytes(mystr);
req.ContentType = "multipart/related;type=\"text/xml\";charset=\"UTF-8\";" + "boundary=\"" + mm.outterboundary.Substring(2) + "\";" + "start=\"" + mm.Start + "\"";
req.ContentLength = fbs.Length;
req.Method = "Post";
req.Headers.Add("SOAPAction", "\"\"");
req.Accept = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
req.KeepAlive = false;
req.Headers.Add("Mime-Version","1.0");
try
{
Form1.WriteLog("test.txt", "Send()--2\r\n");
Stream stm = req.GetRequestStream();
stm.Write(fbs, 0, fbs.Length);
stm.Close();
Form1.WriteLog("test.txt", "Send()--3\r\n");
}
catch
{
}
我是在主线程里面启动了一个发送线程,循环调用这段代码的,测试的时候每次写的内容都相同(一台机器发,一台机器接收),有时写的很快,不到一秒,有时写的很慢居然用1分半钟,搞不明白这是为什么。请各位大侠不吝赐教!