I have some code in python that sends an http request in python, but I am trying to figure out how to do it in ruby since my server is rails.
import urllib2, sys
Although you're calling the remote server as if it responds to application/x-www-form-urlencoded data, in fact it's just responding to a command in the post body.
In Python, urllib2.urlopen's data parameter expects a string that's application/x-www-form-urlencoded
.
select *
isn't really form encoded so to speak, but it's working for you anyway because the server is interpreting it as a query argument named select *
with a None
value, or more precisely, the server sees a post body with select *
and says "I know how to respond to that command".
So, a Ruby equivalent to what you're doing is here.
require 'net/http'
require 'json'
query = "select *"
url = "http://new.openbms.org/backend/api/query"
uri = URI(url)
response = Net::HTTP.post_form(uri, { query => nil })
puts JSON.parse(response.body)