【问题标题】:cURL command to POST with data embedded in request使用嵌入在请求中的数据进行 POST 的 cURL 命令
【发布时间】:2015-11-28 16:24:30
【问题描述】:

我正在编写一个 simple shell 脚本,当使用 curl 满足条件时,我将使用它在 JIRA 中创建一个请求。以下是 JIRA 的执行方式,需要我使用数据文件将发送请求作为命令和参数发送:

请求:

curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/

数据:

{
"fields": {
   "project":
   { 
      "key": "TEST"
   },
   "summary": "REST ye merry gentlemen.",
   "description": "Creating of an issue using project keys and issue type names using the REST API",
   "issuetype": {
      "name": "Bug"
   }}}

所以我不想使用如上所示的单独数据文件。相反,我想使用单个 curl 请求,该请求中嵌入了数据。比如:

curl -D- -u fred:fred -X POST --"**PASS ALL MY DATA HERE**" -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/

我知道这会使事情变得混乱,但这就是我想要的方式。能否请您建议上述是否可行。

【问题讨论】:

    标签: php linux shell api curl


    【解决方案1】:

    你能用here document 做吗?

    curl -D- -u fred:fred -X POST -d - -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/ <<EOF
    {
    "fields": {
      "project":
      { 
        "key": "TEST"
      },
      "summary": "REST ye merry gentlemen.",
      "description": "Creating of an issue using project keys and issue type names using the REST API",
      "issuetype": {
      "name": "Bug"
      }}}
    EOF
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-21
      • 1970-01-01
      • 2020-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多