【问题标题】:How to write RESTful web services client based on curl如何基于 curl 编写 RESTful Web 服务客户端
【发布时间】:2016-03-22 05:26:26
【问题描述】:

我需要为 Delphix 编写一个 RESTful web 服务客户端。我是 delphix 和 RESTful webservices 的新手。如何根据以下 curl 编写客户端。

创建 Delphix API 会话

$ curl -s -X POST -k --data @- http://delphix-server/resources/json/delphix/session\ -c ~/cookies.txt -H "内容类型:应用程序/json"

   Delphix Login 

$ curl -s -X POST -k --data @- http://delphix-server/resources/json/delphix/login \

-b ~/cookies.txt -H "Content-Type: application/json" <<EOF {
"type": "LoginRequest",
"username": "delphix_username",
"password": "delphix_password" } EOF

请帮忙

【问题讨论】:

  • 你已经尝试了什么?你被困在哪里了?
  • Evgeny Lebedev 我知道如何编写一个 RESTful 客户端来使用该服务。但我不知道如何为 Delphix 编写客户端。Delphix Web 服务 API 为每个操作提供 curl 命令。跨度>

标签: java rest curl


【解决方案1】:

只需对 curl 命令使用分解。例如我们看到Authentication 需要两个步骤:

1.创建会话:

使用 JSON 数据向 http://delphix-server/resources/json/delphix/session 发送请求:

{
    "type": "APISession",
    "version": {
        "type": "APIVersion",
        "major": 1,
        "minor": 1,
        "micro": 0
    }
}

您指定 API 版本的位置

2。登录操作:

使用 JSON 数据向 http://delphix-server/resources/json/delphix/login 发出 POST 请求:

{
    "type": "LoginRequest",
    "username": "delphix_username",
    "password": "delphix_password"
}

您的客户端还必须支持 cookie(用于存储身份验证会话)

【讨论】:

  • 所以我们不需要执行 curl 命令。我们可以从 cURL 命令中使用 URL 并继续为 Delphix 编写客户端?
  • 是的,curl 只是一个例子,你的客户端实现了 curl 所做的事情
  • 感谢 Evgeny Lebedev。所以我需要将 json 数据从我的 RESTful 客户端发送到 Delphix 服务。是吗?
  • 是的,带有 post\get(根据 API 要求)和 cookie 支持
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-10
  • 2012-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-30
  • 1970-01-01
相关资源
最近更新 更多