請注意:默認XML-RPC/client.rb IMPL。不支持基於https連接的客戶端證書。如果你想它,你必須使用不同的lib或補丁client.rb的東西,如:
# HG changeset patch
# User Anonymous Coward <[email protected]>
# Date 1338149770 -10800
# Node ID f0557306c8e4f113507fb3bab8567391949fa302
# Parent 3eae8e8f9e065ff6cdf1c95092ad5cca635c9eac
patch client.rb to support https with client certificate.
diff -r 3eae8e8f9e06 -r f0557306c8e4 client.rb
--- a/client.rb Sun May 27 22:20:18 2012 +0300
+++ b/client.rb Sun May 27 23:16:10 2012 +0300
@@ -292,8 +292,8 @@
# Constructors -------------------------------------------------------------------
- def initialize(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil,
- user=nil, password=nil, use_ssl=nil, timeout=nil)
+ def initialize(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil,
+ user=nil, password=nil, use_ssl=nil, timeout=nil, cacert=nil, cert=nil, key=nil)
@http_header_extra = nil
@http_last_response = nil
@@ -311,6 +311,10 @@
if use_ssl
require "net/https"
@port = port || 443
+ @cacert = cacert
+ @cert = cert
+ @key = key
+
else
@port = port || 80
end
@@ -325,8 +329,19 @@
# HTTP object for synchronous calls
Net::HTTP.version_1_2
- @http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port)
- @http.use_ssl = @use_ssl if @use_ssl
+ @http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port)
+ if @use_ssl
+ @http.use_ssl = @use_ssl
+ if nil != @cacert
+ @http.ca_file = @cacert
+ @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
+ @http.verify_depth = 5
+ else
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ end
+ @http.cert = @cert
+ @http.key = @key
+ end
@http.read_timeout = @timeout
@http.open_timeout = @timeout
@@ -366,7 +381,7 @@
hash.each { |k,v| h[k.to_s.downcase] = v }
self.new(h['host'], h['path'], h['port'], h['proxy_host'], h['proxy_port'], h['user'], h['password'],
如果您在文件/ lib目錄/ XMLRPC/README.rdoc有ruby19-stdlib.chm有一些例子。網址可能不是最新的,但總體思路就在那裏。你應該分享你從哪裏得到你的代碼。 – 2013-03-28 16:07:33