首页 Soft PlugIn RAN乱 Dev开发 Info资料 English WAP 留言 登陆 注册
-
Posted by Yippee | 评论(0) | 引用(0) | 阅读38次
20080504 HttpRequst QueryString Headers

20080504 HttpRequst QueryString Headers
http://www.shengfang.org

HttpRequst.QueryString 表示请求路径的查询字符串集合 如
http://community.csdn.net/Expert/TopicView3.asp?id=5702293
中 id/5702293 成一对

HttpRequst.Headers 表示 http 请求头,具体值不一,由用户代理,如浏览器发出,请参考 http 协议规范

protected void Page_Load(object sender, EventArgs e)
    {
        int loop1, loop2;
        NameValueCollection coll = new NameValueCollection();
        coll = Request.QueryString;
        String[] arr1 = coll.AllKeys;
        for (loop1 = 0; loop1 < arr1.Length; loop1++)
        {
            Response.Write("参数:" + arr1[loop1]);
            String[] arr2 = coll.GetValues(arr1[loop1]);
            loop2 = 0;
            Response.Write("值:" + arr2[loop2]+"<br/>");
        }
    }
protected void Page_Load(object sender, EventArgs e)
    {
        int loop1, loop2;
        NameValueCollection coll;

        // Load Header collection into NameValueCollection object.
        coll = Request.Headers;

        // Put the names of all keys into a string array.
        String[] arr1 = coll.AllKeys;
        for (loop1 = 0; loop1 < arr1.Length; loop1++)
        {
            Response.Write("Key: " + arr1[loop1] + "<br/>");
            // Get all values under this key.
            String[] arr2 = coll.GetValues(loop1);
            for (loop2 = 0; loop2 < arr2.Length; loop2++)
            {
                Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br/>");
            }
        }
    }

    ShowRequestHeaders.java 
  package   hall; 
  
  import   java.io.*; 
  import   javax.servlet.*; 
  import   javax.servlet.http.*; 
  import   java.util.*; 
  
  public   class   ShowRequestHeaders   extends   HttpServlet   {  
  public   void   doGet(HttpServletRequest   request, 
  HttpServletResponse   response) 
  throws   ServletException,   IOException   {  
  response.setContentType("text/html"); 
  PrintWriter   out   =   response.getWriter(); 
  String   title   =   "显示所有请求头"; 
  out.println(ServletUtilities.headWithTitle(title)   + 
  "<BODY   BGCOLOR=\"#FDF5E6\">\n"   + 
  "<H1   ALIGN=CENTER>"   +   title   +   "</H1>\n"   + 
  "<B>Request   Method:   </B>"   + 
  request.getMethod()   +   "<BR>\n"   + 
  "<B>Request   URI:   </B>"   + 
  request.getRequestURI()   +   "<BR>\n"   + 
  "<B>Request   Protocol:   </B>"   + 
  request.getProtocol()   +   "<BR><BR>\n"   + 
  "<TABLE   BORDER=1   ALIGN=CENTER>\n"   + 
  "<TR   BGCOLOR=\"#FFAD00\">\n"   + 
  "<TH>Header   Name<TH>Header   Value"); 
  Enumeration   headerNames   =   request.getHeaderNames(); 
  while(headerNames.hasMoreElements())   {  
  String   headerName   =   (String)headerNames.nextElement(); 
  out.println("<TR><TD>"   +   headerName); 
  out.println("   <TD>"   +   request.getHeader(headerName)); 
  } 
  out.println("</TABLE>\n</BODY></HTML>"); 
  } 
  
  public   void   doPost(HttpServletRequest   request, 
  HttpServletResponse   response) 
  throws   ServletException,   IOException   {  
  doGet(request,   response); 
  } 
  }    


字体:


Permanant URI永久地址 http://www.shengfang.org/blog/p/20080504HttpRequstQueryStringHeaders.php
Trackback URI引用地址 http://www.shengfang.org/blog/tb.php?tb_id=1232367443

2009年1月19日20:17星期一  [Dev开发] 追踪此文的RSS
提示:
此文还没有评论。

称呼:    登陆   注册
   不注册,但记住我的信息
邮件:
(非必须)
评论: [UBB代码帮助]
粗体 斜体 下划线 链接 水平线 引用



验证码: 请输入你看见的数字
关闭UBB      提交时自动将内容复制到剪贴板

公告
Fire and Motion!

统计信息
[Yippee]||[统计]||日志:1790
在线: 13||用户: 2562 [列表]
今日:2394||到访:2669341
Rss:837646||评论:1584

最新日志

最新评论

友情链接

日历

最新引用

搜索

归档

杂项
Get RSS Feed (Version 2.0)
Get Atom Feed (Version 0.3)
编码:  UTF-8