无法获得具有相同键名(* http.Header)的响应头

比方说,我有2个标题为“ Set-Cookie”的响应标头

.Get方法只能获取第一个值

在文件中说: To access multiple values of a key,or to use non-canonical keys,access the map directly.

fmt.Println(headers.Get("Set-Cookie"))
// -> Can only get the first one

但是当阅读地图时

for key,value := range headers {
  fmt.Println(key,value)
}
// -> cannot range over headers (type *http.Header)

目前,我不确定读取此数据的正确方法。

lovedanjun 回答:无法获得具有相同键名(* http.Header)的响应头

http.Header已经是map[string][]string,因此不需要传递其地址。如果您以某种方式通过了&request.Header,那么您应该直接通过它而不使用地址。如果您出于某些原因必须通过地址,请在*headers而不是headers范围内>

for key,value := range *headers {
}
,

使用Values代替GetValues返回与给定键关联的所有值。

本文链接:https://www.f2er.com/3162349.html

大家都在问