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条)

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备