zoukankan      html  css  js  c++  java
  • 创建 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 ();
    }
    }
  • 相关阅读:
    安卓第三次作业
    安卓第二次作业
    十三周作业
    2020年5月28日
    十二周上机练习
    十一周作业
    2020年5月14日
    2020年5月7日上机练习
    第九周练习
    Online Tristesse
  • 原文地址:https://www.cnblogs.com/ArRan/p/2747629.html
Copyright © 2011-2022 走看看