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 ();
    }
    }
  • 相关阅读:
    自定义拦截器
    MVP模式网络请求购物车
    mvp+RecyclerView实现网络请求
    二维码扫描
    进度条加载
    画圆移动
    简单排序
    批量发货
    Angular服务
    终极购物车
  • 原文地址:https://www.cnblogs.com/ArRan/p/2747629.html
Copyright © 2011-2022 走看看