HTTP request header: UserAgent variable

后端 未结 2 960
名媛妹妹
名媛妹妹 2020-12-24 07:21

When sending a HTTP request, IE sends the User-Agent variable to the server. A possible value (as seen by the network debugger):

User-Agent: Mozilla /

相关标签:
2条回答
  • 2020-12-24 07:47

    The User-Agent appears in an HTTP Request Header, not an HTTP Response one. In general, the request is sent from browser to the web application. So the user-agent variable is filled by the browser. Different browsers will fill up this field with different values.

    About how IE find those variables, I think you are asking about User-Agent Registry Keys.

    You can also override certain tokens of the user-agent string by adding values to the following registry key.

    HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
       SOFTWARE
          Microsoft
             Windows
                CurrentVersion
                   Internet Settings
                      5.0
                         User Agent
                            (default) = "Mozilla/4.0"
                            Compatible = "compatible"
                            Platform = "Windows NT 5.1"
                            Version = "MSIE 6.0"
                            Pre Platform
                               Token = Value
                            Post Platform
                               Token = Value
    

    The default value of the User Agent key replaces the application name and application version tokens reported in the user-agent string. Be aware that the first seven characters are used for the application name, and the remaining characters specify the application version token.

    The Compatible, Platform, and Version values replace the corresponding tokens in the user-agent string.

    Additional tokens can be added to the user-agent string by using the Registry Editor to create new string values under the Pre-Platform key or Post-Platform key. The value name should be the complete token; the value data is ignored. Tokens added to the Pre-Platform key appear before the platform token in the final user-agent string. Tokens added to the Post-Platform key appear after the platform token in the final user-agent string. Multiple tokens in either the Pre-Platform key or Post-Platform key are displayed in an unpredictable order.

    0 讨论(0)
  • 2020-12-24 07:55

    The Wikipedia article on User Agent states that:

    The User-Agent string format is currently specified by Section 14.43 of RFC 2616 (HTTP/1.1) The format of the User-Agent string in HTTP is a list of product tokens (keywords) with optional comments.

    So I recommend you read the RFC 2616 section about it:

    14.43 User-Agent

    The User-Agent request-header field contains information about the user agent originating the request. This is for statistical purposes, the tracing of protocol violations, and automated recognition of user agents for the sake of tailoring responses to avoid particular user
    agent limitations. User agents SHOULD include this field with
    requests. The field can contain multiple product tokens (section 3.8) and comments identifying the agent and any subproducts which form a
    significant part of the user agent. By convention, the product tokens are listed in order of their significance for identifying the
    application.

       User-Agent     = "User-Agent" ":" 1*( product | comment )
    

    Example:

       User-Agent: CERN-LineMode/2.15 libwww/2.17b3
    

    The section 4.8 about products token states the following:

    3.8 Product Tokens

    Product tokens are used to allow communicating applications to
    identify themselves by software name and version. Most fields using
    product tokens also allow sub-products which form a significant part
    of the application to be listed, separated by white space. By
    convention, the products are listed in order of their significance
    for identifying the application.

       product         = token ["/" product-version]
       product-version = token
    

    Examples:

       User-Agent: CERN-LineMode/2.15 libwww/2.17b3
       Server: Apache/0.8.4
    

    Product tokens SHOULD be short and to the point. They MUST NOT be
    used for advertising or other non-essential information. Although any token character MAY appear in a product-version, this token SHOULD
    only be used for a version identifier (i.e., successive versions of
    the same product SHOULD only differ in the product-version portion of the product value).

    So according to the RFC 2616, the contents of the User Agents is up to the browser. For instance, here is how Mozilla Firefox builds its user agent: https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference

    0 讨论(0)
提交回复
热议问题