【发布时间】:2016-08-21 23:15:55
【问题描述】:
我正在设置这样的标题: 其中文件是 test.txt
size = File.size(file)
h = {
"Content-Type": 'text/plain'
"Content-Length": size.to_s,
"Other-Header": 'some-header'
}
b = File.read(file)
HTTParty.post('/some/api/url', {headers: h , body: b})
请求标头设置如下:
<- "POST /some/api/url\r\n
Content-Type: text/plain\r\n
Content-Length: 16\r\n
Other-Header: some-header\r\n
Connection: close\r\n
Host: somehost.com\r\n
Content-Length: 16\r\n
Content-Type: application/x-www-form-urlencoded\r\n\r\n"
Content-Length 和 Content-Type 被添加和复制,除了 Transfer-Encoding 被设置为 chunked。
如何设置 Content-Length、Content-Type 和 Transfer-Encoding 并避免 HTTParty 自行设置?
希望清楚。
感谢您的宝贵时间!
【问题讨论】:
-
您尝试通过自己设置这些标头来达到什么目的?
-
我正在尝试使用 Backblaze.com api 上传文件。他们的文件要求这样。那里的“原始” net/http 中有一个可行的解决方案。我可以使用它,但我想使用 httparty。 backblaze.com/b2/docs/b2_upload_file.html
标签: ruby http-headers content-type httparty content-length