>我正在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
这尤其令人困惑,因为堆栈跟踪没有说明不允许使用哪种方法。 此错误的原因可能是什么?
您可以
尝试rescue
异常。这样,您可以访问响应的http_body
。如果幸运的话,这可能会让您深入了解出了什么问题。
begin
RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}}
rescue RestClient::Exception => e
puts e.http_body
end