2012-05-21 48 views
2

請您在調用http delete時糾正我在這裏所犯的錯誤。 我得到InternalServerError沒有進一步的解釋。Ruby請求正文和內容類型的Restclient.delete

相同的調用在FireFox RESTClient插件上正常工作。

樣品RESTClient實現

require "rest_client" 
data= {"name" => "foo"} 
res = RestClient.delete(url, data.to_json) 

拋出:/lib/restclient/request.rb:72:in process_url_params': undefined method delete_if」爲#(NoMethodError)

樣品淨/ HTTP

http = Net::HTTP.new('some ip valid', port) 
headers = {'Content-Type' => 'application/json'} 
data = {"name" => "foo"} 
resp, data = http.delete(path, headers) 

引發:Net :: HTTP InternalserverError

回答

0

我有這個問題,並通過刪除json數據部分來解決它。

def doRestDelete(url, values) 
    puts "URL: ", url 
    jsonValues = values.to_json 
    puts jsonValues 
    begin 
     raw = RestClient.delete url # removed this bit ---> , jsonValues 
     puts raw 
    rescue => e 
     abort(e.response) 
    end 
    return JSON.parse(raw) 
end