代码之家  ›  专栏  ›  技术社区  ›  user9812999

在httpHeader spring 4.1.7中,多重映射的第二个键值对不被视为头

  •  0
  • user9812999  · 技术社区  · 6 年前

    我正在发送HttpHeader的键和值,如下所示,只有第一个键和值显示为header。键值的其余部分追加到另一个头值

     MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
    
     headers.add("head1","result1");
     headers.add("head2","result2");
     headers.add("head3","result3");
    
     HttpEntity<String> requestEntity = new HttpEntity<String>("this is a body", headers);
    

    然后我收到了webhook的请求,如下面的链接所示

    请参考以下链接了解extact Format https://webhook.site/#/8362e392-677c-4d29-97db-ba9999bae780/5729b001-de90-4dc5-836f-b0042b526b61/0

    Headers
    content-length  14
    connection  close
    accept-encoding gzip,deflate
    user-agent  Apache-HttpClient/4.5 (Java/1.8.0_161)
    content-type    text/plain;charset=ISO-8859-1
    head1   result1
    accept  text/plain, application/xml, text/xml, application/json,       application/*+xml, application/*+json, */* head2: result2 head3: result3
    host    webhook.site
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Mạnh Quyết Nguyễn    6 年前

    我不确定 MultiValueMap<> 与标题规范兼容。

    换成 HttpHeaders ,它对我有用

     HttpHeaders headers = new HttpHeaders();
    
     headers.add("head1","result1");
     headers.add("head2","result2");
     headers.add("head3","result3");