Mam następujący kod:WP7 aplikacja nigdy nie wychodzi BeginGetResponse i przechodzi do funkcji zwrotnej
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, 0, 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")));
}
Jednak gdy mój kod uderza BeginGetResponse nigdy nie wyjdzie (i nie uderzy punkt przerwania w funkcji GetResponseCallback). Próbowałem dodać wywołanie BeginInvoke, ale wciąż nie wprowadzam tej metody. Ten kod działa w aplikacji konsoli systemu Windows - jest to na Windows Phone 7, że nie robi onn'teorg
Czy ktoś może zobaczyć, co robię źle?
Dzięki.
nie widzę gdzie tworzysz HttpWebRequest –