我有以下代码:
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上,它不具备此功能
谁能看到我做错了什么?
谢谢.
解决方法
原文地址:https://www.jb51.cc/csharp/91563.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。