duanpin2034 2019-01-08 06:26
浏览 1061
已采纳

获取http响应的RAW标头

How to get raw header of response as string like this:

alt-svc: quic=":443"; ma=2592000; v="44,43,39,35"
cache-control: private, max-age=0
content-encoding: br
content-type: text/html; charset=UTF-8
date: Tue, 08 Jan 2019 06:19:47 GMT
expires: -1
server: gws
set-cookie: 1P_JAR=2019-01-08-06; expires=Thu, 07-Feb-2019 06:19:47 GMT; path=/; domain=.google.com
set-cookie: SIDCC=ABtHo-HHNcja-cEEFEUXtBmLOdql4RTVMCWKGApEFFb8lWSAqaTF_fi0gDLoWaCzH3ogvEofah0; expires=Mon, 08-Apr-2019 06:19:47 GMT; path=/; domain=.google.com; priority=high
status: 200

Because I want get the multiple set-cookie value from the response header. Use Http.Response.Header.Get("set-cookies") just return the last row.

Or how can I get the multiple cookies?

  • 写回答

3条回答 默认 最新

  • duan01203 2019-01-08 06:56
    关注

    If you want the raw headers, you'll need to write some wrapper for net.Conn which captures the raw header before it is interpreted by the http library.

    But you don't really seem to need the raw header--or even the full header at all. If your goal is simply to read multiple cookies, the easiest way to do this is with the Cookies method on the response.

    An intermediate option between these two is to read the entire Header field of the response. This will present the full header, but its order is not guaranteed, and minimal parsing will have been done (to remove newlines, etc), so it can't be said this is truly "raw". It does, however, preserve multiple values, in case of duplicate headers, by storing all header values in a []string. So for the purposes of this question, this should be perfectly adequate (although Response.Cookies, as mentioned above, would be easier).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突