在JAVA HttpUrlConnection中,请求Header设置的主要逻辑代码如下:
public synchronized void set(String k, String v) {
for (int i = nkeys; --i >= 0;)
if (k.equalsIgnoreCase(keys[i])) {
values[i] = v;
return;
}
add(k, v);
}
Run Code Online (Sandbox Code Playgroud)
验证密钥应该是唯一的,密钥必须与值保持一对一的映射关系.
相反,在HeaderFields of Response模块中,结构定义为Entry>.也就是说,密钥不与该值保持一对一的映射关系.
为什么是这样?HTTP协议是否有相关协议?
添加:在HttpClient4中,请求Header设置的主要逻辑代码如下:
/**
* Replaces the first occurence of the header with the same name. If no header with
* the same name is found the given header is added to the end of the list.
*
* @param header the new header that should replace the …Run Code Online (Sandbox Code Playgroud)