A
Andrew Stewart
Hello Rubyists,
I am struggling to post data over https and would be grateful for any
help.
I know the server works because I can hit it with curl and get the
response I expect:
curl -d <url-encoded form data> url
When I try to do the same from my Ruby code the server doesn't like it.
The URL to hit looks like:
https://some.host.com/foo/bar.asp?service=someservice
My code looks like:
require 'net/https'
require 'uri'
url = <as above>
uri = URI.parse(url)
request = Net::HTTP.new(uri.host, uri.port)
request.use_ssl = true
request.verify_mode = OpenSSL::SSL::VERIFY_NONE
data = { 'key1' => 'value1',
'key2' => 'value2',
'keyn' => 'valuen' }.map {|k,v| "#{URI.escape
(k.to_s)}=#{URI.escape(v.to_s)}"}.join('&')
response = request.post("#{uri.path}?#{uri.query}", data)
When I tried this with curl, I used the value of data as my url-
encoded form data and everything was fine.
Any ideas?
Thanks in advance,
Andy Stewart
I am struggling to post data over https and would be grateful for any
help.
I know the server works because I can hit it with curl and get the
response I expect:
curl -d <url-encoded form data> url
When I try to do the same from my Ruby code the server doesn't like it.
The URL to hit looks like:
https://some.host.com/foo/bar.asp?service=someservice
My code looks like:
require 'net/https'
require 'uri'
url = <as above>
uri = URI.parse(url)
request = Net::HTTP.new(uri.host, uri.port)
request.use_ssl = true
request.verify_mode = OpenSSL::SSL::VERIFY_NONE
data = { 'key1' => 'value1',
'key2' => 'value2',
'keyn' => 'valuen' }.map {|k,v| "#{URI.escape
(k.to_s)}=#{URI.escape(v.to_s)}"}.join('&')
response = request.post("#{uri.path}?#{uri.query}", data)
When I tried this with curl, I used the value of data as my url-
encoded form data and everything was fine.
Any ideas?
Thanks in advance,
Andy Stewart