How to specify a read timeout for a Net::HTTP::Post.new request in Ruby 2

后端 未结 5 1081
生来不讨喜
生来不讨喜 2021-01-01 13:26

I have a post happening to a rails application from a ruby script. The script creates a variable request as

request = Net::HTTP::Post.new(url.path)
         


        
5条回答
  •  -上瘾入骨i
    2021-01-01 14:03

    If anyone is still facing timeout setting issue and Net::HTTP timeout not working as expected, then you may follow below approach as well:

    begin
        Timeout::timeout(10) {
            ####
            ## YOUR REQUEST CODE WILL BE HERE
            ####
        }
    rescue
        408
    end
    

提交回复
热议问题