4

This is the curl request which I want to convert in ruby:

curl -k --get --data 'session.id=48d59b37-5875-4e49-8d79-6cf097d740f&ajax=executeFlow&project=test&flow=two' https://localhost:8443/executor

I am supposed to the response like this:

{
  "message" : "Execution submitted successfully with exec id 688",
  "project" : "test",
  "flow" : "two",
  "execid" : 688
}

I converted it to the following ruby code:

require 'json'
require 'uri'
require 'net/http'

url = URI("https://localhost:8443/executor")
http = Net::HTTP.new(url.host, url.port)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = (url.scheme == 'https')
request = Net::HTTP::Get.new(url.request_uri)
request.set_form_data({'session.id' => '48d59b37-5875-4e49-8d79-6cf097d740f', 'ajax' => 'executeFlow', 'project' => 'test', 'flow' => 'two'}) 
response = http.request(request)
puts response

But this throws an error page's html code, instead of the expected response. What am I doing wrong here?

Prachi g
  • 849
  • 3
  • 9
  • 23
  • 1
    I think this is where it's wrong `Net::HTTP::Get.new(url.request_uri)`. `url.request_uri` returns `/executor`. I think you need to pass the whole `url` object – PericlesTheo Sep 28 '14 at 18:03
  • In that case, I am getting the following error: NoMethodError: undefined method `empty?' for # – Prachi g Sep 28 '14 at 18:08

1 Answers1

0

This is coming from the Net::HTTP documentation and I have not tested it.

url = URI("https://localhost:8443/executor")
request = Net::HTTP::Post.new(url)
request.set_form_data({'session.id' => '48d59b37-5875-4e49-8d79-6cf097d740f', 'ajax' => 'executeFlow', 'project' => 'test', 'flow' => 'two'}) 

response = Net::HTTP.start(url.hostname, url.port, use_ssl: url.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
  http.request(request)
end
PericlesTheo
  • 2,429
  • 2
  • 19
  • 31