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 ();
    }
    }
  • 相关阅读:
    WPF之长短
    MFC程序和Win32程序的关系
    .NET Framework/CLR之长短
    常用软件
    经典推荐.Net面试法宝
    socket编程原理
    常用开发工具
    Get和Post方法的区别
    MAC IP等相关
    Datagrid为什么不自动换行显
  • 原文地址:https://www.cnblogs.com/ArRan/p/2747629.html
Copyright © 2011-2022 走看看