dongyou2635 2018-03-29 22:11
浏览 139
已采纳

Golang中的原始HTTP响应

I have a request I'm making to an endpoint but however for some reason the response body only contains the last line of the response (the whole response is captured in fiddler). The same thing happens if I recreate the request in python using the requests module. However, I've noticed if I take the entire raw response in python, I am able to see all the lines (separated by multiple ). I'm wondering if it is possible to view the whole raw response in go like with the response.raw.data method in python. In other words is there a way I can view the whole text response instead of it cutting off everything but the last line? If anyone knows as to why the last line is being cut off it will be appreciated greatly as well.

To clarify, this only happens with this single endpoint and I suspect the s in the response body may be the culprit but I am unsure. I've not seen this behaviour from any other http response.

edit: this is the code I'm using to view the response

bodyB, _ := ioutil.ReadAll(resp.Body)
bodyStr := string(bodyB)
  • 写回答

1条回答 默认 最新

  • dpxpz37157 2018-03-29 22:31
    关注

    is a carriage return, but not a new line, so when you print it you are getting all of the lines, but they get overwritten each time.

    You probably will want to do:

    bodyB, _ := ioutil.ReadAll(resp.Body)
    bodyStr := string(bytes.Replace(bodyB, []byte(""), []byte("
    "), -1))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址