gpt4 book ai didi

ruby-on-rails-3 - RestClient::MethodNotAllowed: 405 Method Not Allowed GET 响应

转载 作者:行者123 更新时间:2023-12-04 07:15:26 26 4
gpt4 key购买 nike

我正在 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异常(exception)。这样您就可以访问 http_body的响应。如果幸运的话,这可能会让您深入了解出了什么问题。

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

关于ruby-on-rails-3 - RestClient::MethodNotAllowed: 405 Method Not Allowed GET 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30790897/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com