Ruby CollectiveAccess API的REST客户端
我正在尝试连接到安装在的CollectiveAccess应用程序(它基于Zend framework)的Web服务。 根据“一个人应该这样认证:Ruby CollectiveAccess API的REST客户端,ruby,zend-framework,rest,httpclient,httparty,Ruby,Zend Framework,Rest,Httpclient,Httparty,我正在尝试连接到安装在的CollectiveAccess应用程序(它基于Zend framework)的Web服务。 根据“一个人应该这样认证: http://localhost/ca5/service.php/iteminfo/ItemInfo/rest?method=auth&username=admin&password=123456 http://localhost/service.php/iteminfo/ItemInfo/rest?method=getLabels&
http://localhost/ca5/service.php/iteminfo/ItemInfo/rest?method=auth&username=admin&password=123456
http://localhost/service.php/iteminfo/ItemInfo/rest?method=getLabels&type=ca_objects&item_id=4&mode=all
之后,可以访问API,例如:
http://localhost/ca5/service.php/iteminfo/ItemInfo/rest?method=auth&username=admin&password=123456
http://localhost/service.php/iteminfo/ItemInfo/rest?method=getLabels&type=ca_objects&item_id=4&mode=all
如果我在web浏览器中粘贴URL,这对我来说是可行的,但我无法使用HttpParty的basic_auth或digest_auth方法使其工作。您需要在执行过程中进行身份验证,但请确保HttpParty在会话期间维护初始响应返回的cookie。CA不使用basic_auth和digest_auth-它返回的会话cookie用于维护会话状态。httpclient gem支持即时可用的cookie,以下功能可与CollectiveAccess API配合使用:
require 'httpclient'
clnt = HTTPClient.new
clnt.set_cookie_store('/home/user/cookie.dat')
puts clnt.get('http://localhost/service.php/iteminfo/ItemInfo/rest?method=auth&username=administrator&password=12345').body
puts clnt.get('http://localhost/service.php/iteminfo/ItemInfo/rest?method=getLabels&type=ca_objects&item_id=4&mode=all').body
这里有一些饼干。我会尝试机械化。