我有以下代码:
private void GetRequestStreamCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; // End the operation Stream postStream = request.EndGetRequestStream(asynchronousResult); //Console.WriteLine("Please enter the input data to be posted:"); //string postData = Console.ReadLine(); string postData = "my data"; // Convert the string into a byte array. byte[] byteArray = Encoding.UTF8.GetBytes(postData); // Write to the request stream. postStream.Write(byteArray,postData.Length); postStream.Close(); // Start the asynchronous operation to get the response IAsyncResult result = (IAsyncResult)request.BeginGetResponse(new AsyncCallback(GetResponseCallback),request); } private void GetResponseCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; // End the operation HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); StreamReader streamRead = new StreamReader(streamResponse); string responseString = streamRead.ReadToEnd(); Console.WriteLine(responseString); // Close the stream object streamResponse.Close(); streamRead.Close(); // Release the HttpWebResponse response.Close(); allDone.Set(); Dispatcher.BeginInvoke((Action)(() => Debug.WriteLine("George"))); }
但是,当我的代码命中BeginGetResponse时,它永远不会退出(我在GetResponseCallback函数中没有遇到断点).我尝试添加BeginInvoke调用,但我仍然没有输入此方法.此代码适用于Windows控制台应用程序 – 它位于Windows Phone 7上,它不具备此功能
谁能看到我做错了什么?
谢谢.