Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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} 
like image 202
Jack James Avatar asked Mar 27 '13 20:03

Jack James


People also ask

How do you hide the output of curl command?

The procedure to hide curl progress bar is to pass the -s or --silent option to the curl command: Open the terminal application on your Linux/Unix. Type the command (pass -s option to curl to hide progress bar): $ curl -s https://your-dot-com-domain-name-here/ > /tmp/output. html.

Does curl automatically add headers?

Curl by default adds headers such as Content-type and User-agent .

What is silent mode in curl?

Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute. It will still output the data you ask for, potentially even to the terminal/stdout unless you redirect it.

How do you give headers in curl command?

To send an HTTP header with a Curl request, you can use the -H command-line option and pass the header name and value in "Key: Value" format. If you do not provide a value for the header, this will remove the standard header that Curl would otherwise send. The number of HTTP headers is unlimited.


2 Answers

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...

like image 185
Gilles Quenot Avatar answered Sep 21 '22 01:09

Gilles Quenot


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) 
like image 28
xs2rashid Avatar answered Sep 20 '22 01:09

xs2rashid