我一直在尝试测试 Limesurvey API,并尝试为此制作一个简单的 ruby 脚本。我尝试了以下宝石:
我按照文档中的示例进行操作。对于 rpcjson:
require 'rubygems'
require 'rpcjson'
bc = RPC::JSON::Client.new 'http://localhost/limesurvey/index.php/admin/remotecontrol', 2
bc.get_session_key(username: "xxx", password: "xxx")
但我收到以下错误: JSON::ParserError: A JSON text must at least contains two octets!来自 C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/lib/json/common.rb:1 55:in initialize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/lib/json/common.rb:1
55:in
new' 来自 C:/Ruby193/lib/ruby/gems/ 1.9.1/gems/json-1.8.1/lib/json/common.rb:1 55:in parse'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/lib/json/common.rb:4
68:in
JSON' 来自 C:/Ruby193/lib/ruby/gems/1.9.1/gems/rpcjson-0.0.2/ lib/rpcjson.rb:55 :in method_missing'
from (irb):3
from C:/Ruby193/bin/irb:12:in
'
使用吉姆森:
require 'jimson'
client = Jimson::Client.new('http://localhost/limesurvey/index.php/admin/remotecontrol')
client.get_session_key(username: "xxx", password: "xxx")
我得到:
Jimson::Client::Error::InvalidResponse:来自服务器的无效或空响应。来自 C:/Ruby193/lib/ruby/gems/1.9.1/gems/jimson-0.10.0/lib/jimson/client .rb:75:in process_single_response'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/jimson-0.10.0/lib/jimson/client
.rb:33:in
process_call' 来自 C:/Ruby193/lib/ruby/gems/1.9 .1/gems/jimson-0.10.0/lib/jimson/client .rb:165:in method_missing'
from (irb):4
from C:/Ruby193/bin/irb:12:in
'
有没有人试过这个?提前致谢!