我通过HttpWebRequest发起一个GET的Request,不需要等待服务器返回结果,只要发出请求即可。
请问我该怎么做?
请问我该怎么做?
解决方案 »
- cnblogs博客园模拟评论 winform版
- 用 c# 还是 delphi 开发桌面应用程序?(保证结帖给分)
- asp.net 网站测试 DBHelper.cs 提示我查询的列明无效
- 新人求问 c#中this的用法
- 如何防止正则表达式匹配时死掉?
- 请问如何判断让DateTime.Now.Month.ToString()等返回两位数值?
- 如何以较快的速度实现SByte[]和Byte[]之间的转换?????????????
- 一段C#代码 求分析
- winform 如何展示CGM文件?
- 出错了,为什么呢?这样回写到数据库难道就根本不可能?
- C# validator 正则表达式问题
- 窗体关闭为何引发其他窗体同时关闭
{
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc)); Console.WriteLine("Main thread does some work, then sleeps.");
// If you comment out the Sleep, the main thread exits before
// the thread pool task runs. The thread pool uses background
// threads, which do not keep the application running. (This
// is a simple example of a race condition.)
Thread.Sleep(10000); Console.WriteLine("Main thread exits.");
} // This thread procedure performs the task.
static void ThreadProc(Object stateInfo)
{
// send the http request
HttpWebRequest request = HttpWebRequest.CreateDefault(new Uri("http://www.sina.com.cn")) as HttpWebRequest;
WebResponse response = request.GetResponse();
}
从网上down国一个支持异步的类,测试了一下,每秒大概是7~8个请求发出,现在我需要每秒大概20个。
string strURL = "http://localhost/xxxx/xxxx.aspx?keyword=";
strURL +=this.textBox1.Text;
System.Net.HttpWebRequest request;
//创建一个HTTP请求
request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
//request.Method="get";
System.Net.HttpWebResponse response;
response = (System.Net.HttpWebResponse)request.GetResponse();
System.IO.Stream s;
s = response.GetResponseStream();
XmlTextReader Reader = new XmlTextReader(s);
Reader.MoveToContent();
string strValue = Reader.ReadInnerXml();
strValue = strValue.Replace("<","<");
strValue = strValue.Replace(">",">");
MessageBox.Show(strValue);
Reader.Close();
string uri = " http://server/path/WebForm.aspx";HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);req.Method = "GET";req.MaximumAutomaticRedirections = 3;req.Timeout = 5000;Console.WriteLine("Sending HTTP request");HttpWebResponse res = (HttpWebResponse)req.GetResponse();Stream resst = res.GetResponseStream();StreamReader sr = new StreamReader(resst);Console.WriteLine("HTTP Response is: ");Console.WriteLine(sr.ReadToEnd());sr.Close();resst.Close();