ear*_*old 18 ruby-on-rails rest-client
我正在尝试使用ruby rest-client将大量图像上传到我正在编写的网站.我的代码看起来像:
RestClient.post url, :timeout => 90000000, :open_timeout => 90000000, :file_param => file_obj
Run Code Online (Sandbox Code Playgroud)
但是,我收到此错误:
RestClient::RequestTimeout: Request Timeout
from /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/request.rb:174:in `transmit'
from /Library/Ruby/
Run Code Online (Sandbox Code Playgroud)
但是当我查看服务器日志时
Completed in 61493ms (View: 2, DB: 1) | 201 Created
Run Code Online (Sandbox Code Playgroud)
所以似乎没有任何理由为什么这是超时.任何人都知道如果有超时参数我没有正确设置?
谢谢
phl*_*per 21
此语法将超时设置为请求标头(请参阅RestClient.post签名),如果要使用必须使用的timeout参数:
RestClient::Request.execute(:method => :post, :url => @url, :timeout => 90000000)
Run Code Online (Sandbox Code Playgroud)
请参阅:https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb#L12
cle*_*nsp 13
查看文档,您可以通过RestClient.execute超时参数传递-1:
# * :timeout and :open_timeout passing in -1 will disable the timeout by setting the corresponding net timeout values to nil
Run Code Online (Sandbox Code Playgroud)
它可以使用如下:
resource = RestClient::Resource.new(
"url",
:timeout => -1,
:open_timeout => -1
response = resource.get :params => {<params>}
Run Code Online (Sandbox Code Playgroud)
小智 3
我也有类似的问题。快速深入了解源代码就会发现这种不友好的情况:
def self.post(url, payload, headers={}, &block)
Request.execute(:method => :post, :url => url, :payload => payload, :headers => headers, &block)
end
Run Code Online (Sandbox Code Playgroud)
除非我遗漏了某些内容,否则超时选项不会传递给底层请求。是时候打个补丁了...
归档时间: |
|
查看次数: |
23803 次 |
最近记录: |