使用 Ruby 通过 SSL 进行 XML-RPC:到达文件末尾 (EOFError)
我有一些非常简单的 Ruby 代码,尝试通过 SSL 执行 XML-RPC:
require 'xmlrpc/client'
require 'pp'
server = XMLRPC::Client.new2("https://%s:%d/" % [ 'api.ultradns.net', 8755 ])
pp server.call2('UDNS_OpenConnection', 'sponsor', 'username', 'password')
问题是它总是导致以下 EOFError 异常:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:135:in `sysread': end of file reached (EOFError)
因此,看起来在执行 POST 后,我没有得到任何返回。有趣的是,如果我尝试在 HTTPS 端口上建立 HTTP 连接(反之亦然),这就是我所期望的行为,并且如果我更改协议,实际上我确实会得到相同的异常。我所查看的所有内容都表明,在 URL 中使用“https://”就足以启用 SSL,但我开始怀疑我是否错过了某些内容。
请注意,尽管我在 RPC 中使用的凭据是伪造的,但我预计至少会返回一个 XML 错误页面(类似于访问 https://api.ultradns.net:8755/(使用网络浏览器)。我尝试在 OSX 和 Linux 上运行这段代码,得到完全相同的结果,所以我不得不得出结论,我只是在这里做错了什么。有人有使用 Ruby 通过 SSL 进行 XML-RPC 的示例吗?
I have some very simple Ruby code that is attempting to do XML-RPC over SSL:
require 'xmlrpc/client'
require 'pp'
server = XMLRPC::Client.new2("https://%s:%d/" % [ 'api.ultradns.net', 8755 ])
pp server.call2('UDNS_OpenConnection', 'sponsor', 'username', 'password')
The problem is that it always results in the following EOFError exception:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:135:in `sysread': end of file reached (EOFError)
So it appears that after doing the POST, I don't get anything back. Interestingly, this is the behavior I would expect if I tried to make an HTTP connection on the HTTPS port (or visa versa), and I actually do get the same exact exception if I change the protocol. Everything I've looked at indicates that using "https://" in the URL is enough to enable SSL, but I'm starting wonder if I've missed something.
Note that Even though the credentials I'm using in the RPC are made up, I'm expecting to at least get back an XML error page (similar to if you access https://api.ultradns.net:8755/ with a web browser). I've tried running this code on OSX and Linux with the exact same result, so I have to conclude that I'm just doing something wrong here. Does anyone have any examples of doing XML-RPC over SSL with Ruby?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://www.ultradns.net/api/NUS_API_XML.pdf 明确指出该协议与标准 XML-RPC 客户端不兼容。您需要在方法调用之上添加顶级事务和会话标记。
所以我猜 ruby xml-rpc 解析器只是无法解析响应。只是一个理论。您尝试过其他 xml-rpc 客户端吗?
http://www.ultradns.net/api/NUS_API_XML.pdf explicitly states that the protocol is not compatible with standard XML-RPC clients. You need to add a toplevel transaction and session tag on top of method call.
So I guess the ruby xml-rpc parser is just not being able to parse the response. Just a theory. Have your tried other xml-rpc clients?