0

I have the following block of code, using ruby 2.3.0 and net:http, how do I include a timeout so the server can take more than 60 seconds to respond? I'm having specific challenges with including the array in the body too, when I use something like HttParty

require 'uri'
require 'net/http'
require 'open-uri'

url = URI.parse('http://local-tomcat.com:8080/local-api/v1/anobject/create')
post_params = {"queryToken"=>"4b58f48b-5197-4c86-8783-e15096fe3a6f",
          "tenantId"=>"99218d0e-1757-4fd7-a7c1-5642adcb57e3",
            "projectId"=>"4885536d-06a8-41ed-8002-1619966b14e2",
            "destinations"=>["2cc1053b-20fd-4191-b3f4-219a9099ad63|4885536d-06a8-41ed-8002-1619966b14e2|99218d0e-1757-4fd7-a7c1-5642adcb57e3|5ceabd11-a2b1-4c8e-89b2-c0d75a7d7f8e","515104a7-e4ae-4905-893c-835500f0f962|4885536d-06a8-41ed-8002-1619966b14e2|99218d0e-1757-4fd7-a7c1-5642adcb57e3|5ceabd11-a2b1-4c8e-89b2-c0d75a7d7f8e"],
          "firstExecution"=>true}
response = Net::HTTP.post_form(url, post_params)
puts response.body
Swaroop
  • 431
  • 5
  • 15

1 Answers1

0

Never mind, figured it out:

Net::HTTP.start(url.host, url.port, read_timeout: 999_999) do |http|
  request = Net::HTTP::Post.new(url)
  request.body = URI.encode_www_form(post_params)
  response = http.request request
end
Swaroop
  • 431
  • 5
  • 15
  • I don't think this is a good approach, because you are keeping the server busy .. ideally server should take a request, do a background job, and send a push notification or write to a place, where you can read later – gates Aug 14 '17 at 18:05