0

how can you do a post over https using curb ruby gem?

This is how I do it over http to post a file to a server:

c = Curl::Easy.new("http://www.myserver.com/upload_messages")
c.multipart_form_post = true
post_field = Curl::PostField.content('fieldname', myfile)
c.http_post(post_field) 

With net::http I would use use_ssl = true but how to do it with curb?

The post goes to an application running on heroku and the error I get now is:

Curl::Err::SSLCaertBadFile (Curl::Err::SSLCaertBadFile)

Thanks.

Pod
  • 928
  • 1
  • 10
  • 30

2 Answers2

0

Have you tried c = Curl::Easy.new("https://www.myserver.com/upload_messages") (note the https instead of http on the url), cause in this example (https://github.com/taf2/curb/blob/master/samples/gmail.rb) from Curb's Github (that I suppose works, haven't tried it myself) they post to Gmail through https just doing that.

Jorge Núñez
  • 1,703
  • 12
  • 17
  • Yeah I have tried but I will double check. Actually there I have a variable that takes https in case it is the production environment. But I'll check it again just in case and report back. Thanks Jorge. – Pod Jan 24 '12 at 18:19
0

It seems that you have bad certificates and there should be option to trust unsigned.

require 'net/http'
require 'net/https'
require 'uri'

url = URI.parse 'https://myname:mypass@mail.google.com/'
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = (url.scheme == 'https')
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

Also try curb-fu gem. There you can make ssl post request like

form_data = { :color => 'red', :shape => 'sphere' }
response = CurbFu.post({:url => "https://example.com", :protocol => "https"}, form_data)
Sandvich
  • 110
  • 1
  • 7