LoginSignup
2
0

More than 1 year has passed since last update.

SSLクライアント証明書を使ってRubyのFaradayで通信する方法

Last updated at Posted at 2022-04-13

詰まったのでメモします

前提

  • Ruby: 2.7
  • Faraday: 2.2.0

コード

# urlは通信先のURL
url = 'https://example.com'
connection = Faraday.new(url: url) do |faraday|
    faraday.request  :url_encoded
    faraday.adapter :net_http
    # ファイル名は各自のファイル名
    faraday.ssl.client_cert = OpenSSL::X509::Certificate.new(File.read('ssl_client.crt'))
    builder.ssl.client_key = OpenSSL::PKey::RSA.new(File.read('ssl_client.key'))
end

connection.get(url) do |req|
    req.headers['Content-type'] = 'application/json'
end
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0