C# 发起HTTP请求并检查回应的Cookie数据

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
 
/**
   Examine Cookies. 
   
   To see what cookies a Web Site uses, 
   specify its name on the command line. 
   For example, if you call this program 
   Cookie, then 
    
     Cookie http://MSN.COM 
    
   displays the cookies associated with MSN.COM. 
*/
   
using System; 
using System.Net; 
   
public class CookieDemo {  
  public static void Main(string[] args) { 
   
    if(args.Length != 1) { 
      Console.WriteLine("Usage: CookieDemo <uri>"); 
      return ; 
    } 
   
    // Create a WebRequest to the specified URI. 
    HttpWebRequest req = (HttpWebRequest) 
           WebRequest.Create(args[0]);  
   
    // Get an empty cookie container. 
    req.CookieContainer = new CookieContainer(); 
   
    // Send the request and return the response. 
    HttpWebResponse resp = (HttpWebResponse) 
           req.GetResponse(); 
   
    // Display the cookies. 
    Console.WriteLine("Number of cookies: " +  
                        resp.Cookies.Count); 
    Console.WriteLine("{0,-20}{1}", "Name", "Value"); 
   
    for(int i=0; i < resp.Cookies.Count; i++) 
      Console.WriteLine("{0, -20}{1}", 
                         resp.Cookies[i].Name, 
                         resp.Cookies[i].Value); 
   
    // Close the Response.  
    resp.Close(); 
  } 
}


标签: isp

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇: android 利用socket 发送Json数据demo

下一篇:python多线程多队列