知其然知其所以然出处:HttpWebRequest.GetRequestStream() 方法 为什么不能在很短的时间里多次提交,为什么会有延时

来源:百度文库 编辑:高校问答 时间:2024/04/28 06:06:51
我用httpwebRequest 写了一个向网上不断提交数据的程序,可是要用在执行多次提交时,会出现,第1,2次很快,第3次要等90秒,第4,5次很快,第6次又要等,总是这样
请大家帮忙
object headers = "Content-Type:application/x-www-form-urlencoded\n";
string postData="要提交的数据";
//string.Intern(postData);
string url = @"提交地址";

//新建一个CookieContainer来存放Cookie集合
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
//新建一个HttpWebRequest
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";
myHttpWebRequest.Accept = "*/*";
//myHttpWebRequest.Referer = "";
myHttpWebRequest.KeepAlive = false;
myHttpWebRequest.ContentLength = postData.Length;

myHttpWebRequest.Method = "POST";
myHttpWebRequest.CookieContainer = myCookieContainer;
//设置HttpWebRequest的CookieContainer为刚才建立的那个myCookieContainer

Stream myRequestStream = myHttpWebRequest.GetRequestStream();

StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));

myStreamWriter.Write(postData);

myStreamWriter.Dispose();
myRequestStream.Dispose();
myStreamWriter.Close();
myRequestStream.Close();