2014-04-26 64 views
0
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餅乾,用戶代理,X-會話級ID永遠得不到發出的請求...我確認使用wiresharkREST客戶端(紅寶石)不設置Cookie當我嘗試上傳的文件

我做錯了什麼?

回答

2

當RestClient檢測到一個文件並將其餘參數作爲多部分請求中的其他部分處理時,RestClient會試圖變得智能。所以你只需要將內容從標題中分離出來就可以把它變成一個散列。

試試這個:

response = RestClient.post "URL", 
          {"myfile" => File.new("/path/to/file")}, 
          "Cookie" => "Name=michal", 
          "X-SESSION-ID" => "dsafasdfadsfadsfasfdadf", 
          "User-Agent" => "UNknow", 
          "connection" => "Keep-Alive"