创建 WebRequest 实例并返回响应
public class WebRequestGetExample
{
public static void Main ()
{
// Create a request for the URL.
WebRequest request = WebRequest.Create ("http://www.cnblogs.com/kingdom_0");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
// 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 = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Cleanup the streams and the response.
reader.Close ();
dataStream.Close ();
response.Close ();
}
}

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2021-10-16
  • 2021-09-03
  • 2021-05-29
  • 2021-11-11
  • 2022-12-23
猜你喜欢
  • 2021-10-02
  • 2022-02-17
  • 2021-05-17
  • 2021-10-28
  • 2022-12-23
  • 2022-01-07
  • 2021-09-12
相关资源
相似解决方案