2011-07-04 179 views
5

我試圖通過RESTClient實現的HTTP POST request.This發送XML到另一個網站服務器是代碼:HTTP POST錯誤

response = RestClient.post 'https://secure.rowebooks.co.uk/testorders/orders.aspx', :content_type => "text/xml", :myfile => File.read("#{Rails.root}/public/shared/#{@book}.xml") 

但我發現了這個錯誤

ERROR 2 Data at the root level is invalid. Line 1, position 1.ERROR3 Object reference not set to an instance of an object. 

我有人告訴我,我收到了這個錯誤,因爲XML文件不在調用的內容中。它必須在內容中。我不知道這是什麼意思。

任何建議/線索將不勝感激。

感謝

回答

1

你應該這樣做的:

response = RestClient.post('https://secure.rowebooks.co.uk/testorders/orders.aspx', 
File.read("#{Rails.root}/public/shared/#{@book}.xml"), 'Content-Type' => 'text/xml') 
+0

嗨,您的回覆,但你的代碼貼返回錯誤謝謝 - 「語法錯誤,意想不到的‘\ n’,期待tASSOC」 。有什麼遺漏嗎? – safalmj

+0

吶喊,小錯字,現在是正確的。 –

+0

非常感謝Mauricio。我非常感謝你的幫助。 – safalmj