require 'rubygems'
require 'rest_client'
response = RestClient.post "URL",
"myfile" => File.new("/path/to/file"),
"Cookie" => "Name=michal",
"X-SESSION-ID" => "dsafasdfadsfadsfasfdadf",
"User-Agent" => "UNknow",
"connection" => "Keep-Alive"
如果我尝试使用上述代码发布文件,那么headers
Cookie,用户代理,X-SESSION-ID 永远不会被设置在发出请求...我使用wireshark
我做错了什么?
答案 0 :(得分:2)
RestClient在检测到文件时会尝试智能,并将其余参数视为多部分请求中的其他部分。因此,您只需将内容与标题分开即可将其更改为哈希值。
试试这个:
response = RestClient.post "URL",
{"myfile" => File.new("/path/to/file")},
"Cookie" => "Name=michal",
"X-SESSION-ID" => "dsafasdfadsfadsfasfdadf",
"User-Agent" => "UNknow",
"connection" => "Keep-Alive"