How can I suppress the headers from CLI CURL's output of request

旧时模样 提交于 2019-12-08 14:42:17

问题


There's plenty of info on how to prevent curl from showing header information when doing a request for the PHP version, but seemingly nothing for the CLI version.

my request is in the form

curl -i -X POST -H 'Content-Type: application/json; charset=UTF-8' -H 'X-Accept: application/json' -H '-d '{"somedata":"12ihiuhihihed994f63dbef6b012b"}' https://myurl.com/v3/oauth/request

Which works, but returns this:

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json
Date: Wed, 27 Mar 2013 20:42:11 GMT
P3P: policyref="/w3c/p3p.xml", CP="ALL CURa ADMa DEVa OUR IND UNI COM NAV INT STA PRE"
Server: Apache/2.2.23 (Amazon)
Status: 200 OK
X-Powered-By: PHP/5.3.20
Content-Length: 54
Connection: keep-alive

{"code":"jkhjhhjhaa","state":null}

when all I really want is this:

{"code":"jkhjhhjhaa","state":null}

回答1:


Simply remove the -i switch from your curl command.

man curl

said :

-i, --include
(HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-name, date of the document, HTTP-version and more...




回答2:


In order to suppress output from CURL CLI --silent option can be used. It perfectly works when curl output is piped as well.

-s, --silent        Silent mode (don't output anything)


来源:https://stackoverflow.com/questions/15669050/how-can-i-suppress-the-headers-from-cli-curls-output-of-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!