开发者

Ruby/Rails client to HTTPS API

I need to deal with some third-party API, which is require https connection. I even have a certificate file mycert.pem and try to connect with API this way:

https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.ca_file = File.join(Rails.root, "data", "certs", "mycert.pem")
https.ca_path = [Rails.root, "data", "certs"].join("/")

https.start {
  data = {
      <here some request data>
  }.to_json

  https.request_post([API_HOST, API_URL].join('/'), data) {|res|
    print res.body
  }
}

But I always have authorization error form this API, just like I have invalid (or obsolete) certificate. Even I'm sure that this is not true and my client p开发者_高级运维roblem, cause other client connects with this API (and same certificate) with no problem.

So, question is

what is the right way to https connect with service from ruby? Maybe I've lost something or do something wrong?


I don't have the answer for that specific problem but you can try a lot of libraries for doing this that may help you around.

Check out this awesome slideshow comparison:

http://www.slideshare.net/HiroshiNakamura/rubyhttp-clients-comparison

I'm using faraday for my projects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜