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"
If I try to use the above code to post a file then the headers
Cookie,User-Agent,X-SESSION-ID never gets set on the request that is send out... i confirmed it using wireshark
What am i doing wrong ?
RestClient tries to be smart when it detects a file and treat the remaining arguments as other parts in the multipart request. So you just need to separate the content from the headers by change it into a hash.
Try this:
response = RestClient.post "URL",
{"myfile" => File.new("/path/to/file")},
"Cookie" => "Name=michal",
"X-SESSION-ID" => "dsafasdfadsfadsfasfdadf",
"User-Agent" => "UNknow",
"connection" => "Keep-Alive"