From: Aaron Patterson Date: 2006-10-10T00:52:36+09:00 Subject: Re: Posting over https On Tue, Oct 10, 2006 at 12:04:26AM +0900, Andrew Stewart wrote: > 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 > > 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 = > 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? Try using Mechanize. You can post forms over https with it, and you won't have to deal with encoding query parameters or setting up Net::HTTP. http://mechanize.rubyforge.org/ --Aaron -- Aaron Patterson http://tenderlovemaking.com/