我把header设置成这样:其中文件是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自己设置它们?
希望没什么事。
Thx for your time!
1条答案
按热度按时间8wtpewkr1#
试试这个