Unable to read data from the transport connection: The connection was closed.
有个问题请教一下:
HttpWebResponse^ response;
String^ responseFromServer = "";
try
{
// Create a request for the URL.
//WebRequest^ request = WebRequest::Create( "http://www.komennorthnv.org");
HttpWebRequest^ request = (HttpWebRequest^)( WebRequest::Create( strURL ) );
request->Accept = "*/*";
request->Timeout = 60000;
// If required by the server, set the credentials.
request->Credentials = CredentialCache::DefaultCredentials;
// Get the response.
response = (HttpWebResponse^)( request->GetResponse() );
}
catch (WebException^ e)
{
}
catch (Exception ^ e)
{
}
finally
{
if (response
&& response->StatusCode == HttpStatusCode::OK
&& response->ContentType->ToLower()->Contains("text/html"))
{
// Display the status.
//Console::WriteLine( response->StatusDescription );
// Get the stream containing content returned by the server.
Stream^ dataStream = response->GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader^ reader = gcnew StreamReader( dataStream );
//if(reader->EndofStream())
responseFromServer = reader->ReadToEnd();
// Cleanup the streams and the response.
reader->Close();
dataStream->Close();
response->Close();
}
}
上面一段程序,会在responseFromServer = reader->ReadToEnd();这一行报错,
Additional information: Unable to read data from the transport connection: The connection was closed.
该如何解决呢?