curb post over ssl

2.3k views Asked by At

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.

2

There are 2 answers

1
Jorge Núñez On

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.

0
Sandvich On

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:[email protected]/'
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)