我正在尝试通过 gorequest PUT 方法发送 html 文件的内容。在我尝试联系的服务文档中提到,正文类型应该是 Content-Type: application/octet-stream.
当我执行时:
req.Send(string(content))
其中内容是字节 slice ([]byte
),我的 html 文件已损坏,因为文件的内容已编码,所有空格、<、> 等特殊字符都被替换了。
当我执行时:
req.Send(content)
我看到发送了以下内容:[60,104,116,109, .... ]
这不是我所期望的。你能告诉我如何使用 gorequest 将 html 文件作为字节流传输到 web 服务吗?
最佳答案
在发送字符串之前将 req.BounceToRawString
设置为 true
或将内容类型更改为 text/plain
。
来自 godoc.org 的文档:
If you have set Type to text or Content-Type to text/plain, content will be sent as raw string in body instead of form
关于go - 如何使用gorequest发送二进制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35017735/