zoukankan      html  css  js  c++  java
  • C# Http Response Header 打印

        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("****************************************************************\n");
                Console.WriteLine("Http Response Header Resolver V1.00.00\n");
                Console.WriteLine("input a url for example:www.google.com\n");
                Console.WriteLine("input q to quit the program\n");
                Console.WriteLine("****************************************************************\n");
    
                while(true)
                {
                    Console.Write(">");
                    string url = Console.ReadLine();
    
                    if(url=="q")
                    {
                        break;
                    }
    
                    try
                    {
    
                        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://" + url);
                        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    
                        //协议版本号,状态码,状态描述
                        Console.WriteLine(String.Format("{0,-20}HTTP/{1} {2:d} {3}","(Status-Line)",response.ProtocolVersion,response.StatusCode,response.StatusDescription));
                        
                        //Http response头
                        for(int i=0;i<response.Headers.Keys.Count;i++)
                        {
                            Console.WriteLine(String.Format("{0,-20}{1}",response.Headers.Keys[i],response.Headers.Get(i)));
                        }
    
                        foreach(Cookie c in response.Cookies)
                        {
                            Console.WriteLine(c.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }
    

      

  • 相关阅读:
    Python 类 元类 new之间的关系
    Scrapy Item类分析
    python中的可变参数和不可变参数
    简易python购物车
    关于Javascrip瀑布流深度解析
    python3.5 的str类型和bytes类型的转换
    php 扩展
    PHP开源网
    ElementUI中树形控件el-tree修改样式/添加title
    SVN 重命名文件夹
  • 原文地址:https://www.cnblogs.com/oyjj/p/2164417.html
Copyright © 2011-2022 走看看