有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安卓中HttpURLConnection中getHeaderFields与getRequestProperties之间的java差异

我在浏览HttpURLConnectionAPI文档时发现了两种方法

getHeaderFields ()返回响应头字段和值的不可修改映射

getRequestProperties (),它还返回此连接使用的常规请求属性的不可修改映射

我想知道这两种方法的区别是什么

据我所知,这两种方法都用于在HTTP头中存储密钥、值对

如果我错了,请纠正我

提前谢谢


共 (2) 个答案

  1. # 1 楼答案

    从<;Android API 22平台>;javaDoc:

    public Map<...> getHeaderFields ()
    Added in API level 1
    Returns an unmodifiable map of the response-header fields and values. The response-header field names are the key values of the map. The map values are lists of header field values associated with a particular key name. Some implementations (notably HttpURLConnection) include a mapping for the null key; in HTTP's case, this maps to the HTTP status line and is treated as being at position 0 when indexing into the header fields.

    Returns
    the response-header representing generic map

    和请求

    public Map<...> getRequestProperties ()
    Added in API level 1
    Returns an unmodifiable map of general request properties used by this connection. The request property names are the key values of the map. The map values are lists of property values of the corresponding key name.
    Returns
    the request-property representing generic map.

  2. # 2 楼答案

    getHeaderFields()返回所有字段和值,而getRequestProperties(String field)返回请求字段的属性(不是全部)