RestClient :: MethodNotAllowed:405方法不允许GET响应

时间:2015-06-11 20:32:35

标签: ruby-on-rails-3 rest-client

我在Ruby中执行GET请求,但不确定为什么我有时会得到以下堆栈跟踪。

RestClient::MethodNotAllowed: 405 Method Not Allowed
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient/abstract_response.rb:48:in return!
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient/request.rb:269:in process_result
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient/request.rb:212:in block in transmit
/usr/lib/ruby/2.0.0/net/http.rb:852:in start
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient/request.rb:206:in transmit
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient/request.rb:68:in execute
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient/request.rb:35:in execute
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient.rb:70:in get

这特别令人困惑,因为堆栈跟踪没有说明不允许哪种方法。可能是导致此错误的原因是什么?

1 个答案:

答案 0 :(得分:5)

您可以尝试rescue例外。这样您就可以访问响应的http_body。如果你很幸运,这可能会让你了解出了什么问题。

begin
  RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}}
rescue RestClient::Exception => e
  puts e.http_body
end