zoukankan      html  css  js  c++  java
  • CookieContainer

    HttpWebRequest属性提供CookieContainer类的一个实例,该实例包含与此请求关联的 cookie。

     1         CookieContainer c = new CookieContainer();    //声明一个CookieContainer
     2         HttpWebRequest requset = (HttpWebRequest)WebRequest.Create("URL1登录页");
     3         requset.CookieContainer = c;      //登录相关的Cookie
     4         HttpWebResponse respons = (HttpWebResponse)requset.GetResponse();
     5         
     6         Stream dataStream = respons.GetResponseStream();
     7         StreamReader reader = new StreamReader(dataStream, System.Text.Encoding.GetEncoding("gb2312"));
     8         string s = reader.ReadToEnd();
     9         dataStream.Close();
    10         reader.Close();
    11 
    12         requset = (HttpWebRequest)WebRequest.Create("URL2其他页面");
    13         requset.CookieContainer = c;     //呆着登录相关的Cookie去访问内部页面
    14         respons = (HttpWebResponse)requset.GetResponse();
    15 
    16         dataStream = respons.GetResponseStream();
    17         reader = new StreamReader(dataStream, System.Text.Encoding.GetEncoding("gb2312"));
    18         s = reader.ReadToEnd();
    19         dataStream.Close();
    20         reader.Close();
    21         Response.Write(s);  
  • 相关阅读:
    Unique Binary Search Trees 解答
    Unique Paths II 解答
    Unique Paths 解答
    Maximum Subarray 解答
    Climbing Stairs 解答
    House Robber II 解答
    House Robber 解答
    Valid Palindrome 解答
    Container With Most Water 解答
    Remove Duplicates from Sorted List II 解答
  • 原文地址:https://www.cnblogs.com/wupeiqi/p/2767803.html
Copyright © 2011-2022 走看看