supress verbose并仅显示curl输出命令

时间:2018-04-03 14:39:09

标签: linux shell curl

我正在使用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块一样。

3 个答案:

答案 0 :(得分:1)

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

curl man page

答案 1 :(得分:1)

您应该只需要省略-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.

答案 2 :(得分:0)

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

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