<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    阿郎的技術(shù)搏客

    成長軌跡

    How to Read the Value of an HTTP Header

    How to Read the Value of an HTTP Header

    In the above sections, we have gone through several HTTP headers that are useful for user agent detection and device capabilities detection. Now one essential question remains: how to read the value of an HTTP header?

    Reading the value of an HTTP header is not difficult. Just use a server-side scripting technology to write a few lines of code. We will demonstrate how to read the value of an HTTP header using ASP, Java Servlet / JSP, Perl and PHP below.

    Retrieving HTTP Headers with ASP
    In ASP, you can use the ServerVariables collection of the Request object to retrieve the value of HTTP headers. You can choose either VBScript or JScript (JavaScript implemented by Microsoft) as the scripting language. If you use VBScript, the code for reading HTTP headers should be like this:

     ' Declaring variables
    Dim accept
    Dim user_agent
    Dim accept_charset
    Dim accept_language
    Dim x_wap_profile
    Dim profile

    accept = Request.ServerVariables("HTTP_ACCEPT")
    user_agent = Request.ServerVariables("HTTP_USER_AGENT")
    accept_charset = Request.ServerVariables("HTTP_ACCEPT_CHARSET")
    accept_language = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
    x_wap_profile = Request.ServerVariables("HTTP_X_WAP_PROFILE")
    profile = Request.ServerVariables("HTTP_PROFILE")

     As you can see above, to retrieve the value of an HTTP header in ASP, we use Request.ServerVariables("HTTP_x"), where x is the HTTP header name with all the "-" characters replaced with the "_" character. ASP has other pre-defined server environment variables that can be placed inside the parentheses of ServerVariables() but we are not going to discuss about them since they are not useful to us here.

    If you use JScript, the code for reading HTTP headers should look like this:

     


    var accept = Request.ServerVariables("HTTP_ACCEPT");
    var user_agent = Request.ServerVariables("HTTP_USER_AGENT");
    var accept_charset = Request.ServerVariables("HTTP_ACCEPT_CHARSET");
    var accept_language = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE");
    var x_wap_profile = Request.ServerVariables("HTTP_X_WAP_PROFILE");
    var profile = Request.ServerVariables("HTTP_PROFILE");

     Retrieving HTTP Headers with Java Servlet / JSP
    In Java Servlet or JSP, you can use the getHeader() method of the javax.servlet.http.HttpServletRequest object to retrieve the value of HTTP headers. Here is the code for reading HTTP headers:

     String accept = request.getHeader("accept");
    String user_agent = request.getHeader("user-agent");
    String accept_charset = request.getHeader("accept-charset");
    String accept_language = request.getHeader("accept-language");
    String x_wap_profile = request.getHeader("x-wap-profile");
    String profile = request.getHeader("profile");

     As you can see, to retrieve the value of an HTTP header whose name is x in Java Servlet or JSP, we use request.getHeader("x"), where request is an instance of the javax.servlet.http.HttpServletRequest class.

     Retrieving HTTP Headers with Perl
    In Perl, the values of HTTP headers are stored in the %ENV hash. Here is the code for retrieving HTTP headers:

     $accept = $ENV{"HTTP_ACCEPT"};
    $user_agent = $ENV{"HTTP_USER_AGENT"};
    $accept_charset = $ENV{"HTTP_ACCEPT_CHARSET"};
    $accept_language = $ENV{"HTTP_ACCEPT_LANGUAGE"};
    $x_wap_profile = $ENV{"HTTP_X_WAP_PROFILE"};
    $profile = $ENV{"HTTP_PROFILE"};

     As you can see above, to retrieve the value of an HTTP header in Perl, we use $ENV{"HTTP_x"}, where x is the HTTP header name with all the "-" characters replaced with the "_" character. Perl has other pre-defined values that can be placed inside the braces of $ENV{} but we are not going to discuss about them since they are not useful to us here.

     Retrieving HTTP Headers with PHP

    In PHP, the value of HTTP headers are stored in the $_SERVER array. Here is the code for retrieving HTTP headers:

     $accept = $_SERVER["HTTP_ACCEPT"];
    $user_agent = $_SERVER["HTTP_USER_AGENT"];
    $accept_charset = $_SERVER["HTTP_ACCEPT_CHARSET"];
    $accept_language = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
    $x_wap_profile = $_SERVER["HTTP_X_WAP_PROFILE"];
    $profile = $_SERVER["HTTP_PROFILE"];

     As you can see above, to retrieve the value of an HTTP header in PHP, we use $_SERVER["HTTP_x"], where x is the HTTP header name with all the "-" characters replaced with the "_" character. PHP has other pre-defined values that can be placed inside the square brackets of $_SERVER[] but we are not going to discuss about them since they are not useful to us here

    posted on 2007-04-30 10:34 alone 閱讀(867) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 深夜特黄a级毛片免费播放| 国产亚洲欧美在线观看| 国产无遮挡裸体免费视频在线观看| 永久免费视频v片www| 亚洲精品无码久久久久APP | 精品日韩亚洲AV无码| 亚洲a一级免费视频| 亚洲精品无码久久久久久久 | 亚洲精品欧洲精品| 国产精品亚洲αv天堂无码| 免费一级做a爰片久久毛片潮| 毛片免费观看网址| 亚洲小说图区综合在线| 国产成人免费ā片在线观看| 美女扒开屁股让男人桶爽免费| 亚洲精品无码久久久久AV麻豆| yellow视频免费在线观看| 国产亚洲人成网站观看| 99在线免费观看视频| 亚洲一区二区三区亚瑟| 国产91久久久久久久免费| 中文字幕免费在线看电影大全 | 亚洲AV无码精品无码麻豆| 精品成在人线AV无码免费看 | 亚洲日本乱码一区二区在线二产线| 最近高清中文字幕无吗免费看| 亚洲中文无码mv| 久久精品国产亚洲Aⅴ蜜臀色欲| 免费无码H肉动漫在线观看麻豆| 亚洲综合激情视频| 国产高清免费观看| 日本高清免费观看| 国产AV旡码专区亚洲AV苍井空| 亚洲精品色婷婷在线影院| 一级毛片在线免费看| 老子影院午夜伦不卡亚洲| 亚洲国产精品无码AAA片| 毛片基地免费视频a| 国产在线观看免费av站| 亚洲一区二区三区高清不卡| 日本中文一区二区三区亚洲 |