我在 httpWebRequest 中从来都不是很好。总是首选 WebClient,但......绝望的时间,绝望的措施。
private static void GetResponseCallback(IAsyncResult asynchronousResult)
{
try
{
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();
// Close the stream object
streamResponse.Close();
streamRead.Close();
// Release the HttpWebResponse
response.Close();
//allDone.Set();
}
catch (WebException exception)
{
}
}
我可以看到(当我下一个断点时)responseString 是漂亮的 JSON,但我无法将其打印出来(MessageBox 等),因为我的应用程序会中断。
你能告诉我如何处理吗?干杯