【问题标题】:REST client for CollectiveAccess APICollectiveAccess API 的 REST 客户端
【发布时间】:2012-03-06 18:03:43
【问题描述】:

我正在尝试连接到安装在 http://localhost 的 CollectiveAccess 应用程序(它基于 Zend 框架)的 Web 服务。 根据documentation`,应该像这样进行身份验证:

http://localhost/ca5/service.php/iteminfo/ItemInfo/rest?method=auth&username=admin&password=123456

然后,可以像这样访问 API:

http://localhost/service.php/iteminfo/ItemInfo/rest?method=getLabels&type=ca_objects&item_id=4&mode=all

如果我将 URL 粘贴到网络浏览器中,这对我有用,但我无法使用 HTTParty 的 basic_auth 或 digest_auth 方法使其工作。

【问题讨论】:

  • 这里有一些 cookie。我会尝试机械化。

标签: ruby zend-framework rest httpclient httparty


【解决方案1】:

您需要进行身份验证,但请确保 HTTParty 在会话期间维护初始响应返回的 cookie。 CA 不使用 basic_auth 和 digest_auth - 它返回的会话 cookie 用于维护会话状态。

【讨论】:

    【解决方案2】:

    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
    

    【讨论】:

      猜你喜欢
      • 2017-08-11
      • 1970-01-01
      • 1970-01-01
      • 2018-09-06
      • 1970-01-01
      • 1970-01-01
      • 2013-08-30
      • 2019-11-25
      • 2011-06-25
      相关资源
      最近更新 更多