【问题标题】:supress verbose and show only curl output command抑制详细并仅显示 curl 输出命令
【发布时间】:2018-04-03 14:39:08
【问题描述】:

我正在使用 curl 命令,如下所示 curl -i -X POST -H 'Content-type:application/json' some_url -d '{ "some":"json"}' 并获得如下输出。

HTTP/1.1 200 OK
Server: openresty
Date: Tue, 03 Apr 2018 14:28:38 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 3925
Connection: keep-alive
X-Powered-By: PHP/5.5.9-1ubuntu4.23
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000

{
    "jsonrpc": "2.0",
    "result": [{
        "hostid": "10225",
        "proxy_hostid": "0",
        "host": "sgw-2585-bus",
        "status": "0"
    }]
}

我只希望 curl 命令的 json 输出用于进一步处理。我怎样才能实现它。

注意:curl 不会像这样显示 json 输出,我已经格式化了 json 块。

【问题讨论】:

    标签: linux shell curl


    【解决方案1】:

    您是否尝试过 -s 或 --silent 选项?

    curl man page

    【讨论】:

      【解决方案2】:

      您应该只需要省略 -i 标志

      来自 curl 手册页:

         -i, --include
                Include the HTTP-header in the output. The HTTP-header includes things like server-name, date of the document, HTTP-version and more...
      
                See also -v, --verbose.
      

      【讨论】:

        【解决方案3】:

        只需从您的命令中删除 -i 开关。下面的代码给出了你的纯 JSON 响应

        curl -s -X POST -H 'Content-type:application/json' some_url -d '{ "some":"json"}'
        

        【讨论】:

          猜你喜欢
          • 2016-08-29
          • 1970-01-01
          • 2015-08-23
          • 1970-01-01
          • 2019-06-25
          • 1970-01-01
          • 1970-01-01
          • 2012-07-12
          • 2016-04-25
          相关资源
          最近更新 更多