如何使用证书验证http Web请求?

我需要能够向需要客户端使用特定证书进行身份验证的Web服务发送http get请求。 .net代码如下所示:
if (certificate != null) 
    request.ClientCertificates.Add(certificate); 
return request; 
我还没能弄清楚轨道中的等价物。有什么建议?     
已邀请:
如果使用基本的net / https,那么它非常简单:
require 'net/https'
require 'uri'

uri = URI.parse(ARGV[0] || 'https://localhost/')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == "https"  # enable SSL/TLS
http.key = pkey #Sets an OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
http.cert= cert #Sets an OpenSSL::X509::Certificate object as client certificate

http.start {
  http.request_get(uri.path) {|res|
    print res.body
  }
}
如果将它们组合在一起,则必须使用一些openssl实用方法对它们进行按摩。 对于自定义http客户端,您应该阅读ruby openssl库的文档以获取详细信息。 但简而言之,这样的事情应该有效:
ctx = OpenSSL::SSL::SSLContext.new
ctx.key = private_key_file
ctx.cert = certificate_file
..然后为您的连接提供上下文。     

要回复问题请先登录注册