我通过HttpWebRequest发起一个GET的Request,不需要等待服务器返回结果,只要发出请求即可。
请问我该怎么做?

解决方案 »

  1.   

    public static void SendHttpRequest()
            {
                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();
            }
      

  2.   


    从网上down国一个支持异步的类,测试了一下,每秒大概是7~8个请求发出,现在我需要每秒大概20个。
      

  3.   


    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("&lt;","<");
       strValue = strValue.Replace("&gt;",">");
       MessageBox.Show(strValue); 
       Reader.Close();
      

  4.   


    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();