I post file to url and would like to read all headers output in curl console. What parameter should I add?
curl -F file=@"c:\Word.docx" http://do.convertapi.com/Word2Pdf > output.pdf
We can use curl -v or curl -verbose to display the request headers and response headers in the cURL command. The > lines are request headers . The < lines are response headers .
To view the request or response HTTP headers in Google Chrome, take the following steps : In Chrome, visit a URL, right click , select Inspect to open the developer tools. Select Network tab. Reload the page, select any HTTP request on the left panel, and the HTTP headers will be displayed on the right panel.
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.
The -I option is used to tell curl to only fetch the HTTP headers ( HEAD method) of a particular page or resource.
Use -i
From the cURL manual
-i, --include Include protocol headers in the output (H/F)
Note also:
-I, --head Show document info only
The first will show headers, followed by body. The second will send a HEAD request so can't be used in your example as you're POSTing data.
Edit
The header output using -i
is echoed to stdout, the same as the request body so directing the response into a PDF file will create an invalid PDF.
So I suggest instead you use -v
which will be much noisier, but will show headers on command line when directing stdout to file, because verbose output goes to stderr.
In Unix and Unix-like systems the following submits the request, writing the response headers to the console and saving the response body to output.pdf
:
curl -F file=@"c:\Word.docx" http://do.convertapi.com/Word2Pdf \
--output output.pdf --dump-header /dev/fd/1 --silent | tail -n +2
The --output output.pdf
option outputs the results to output.pdf
.
-o, --output <file> Write output to <file> instead of stdout.
The --dump-header /dev/fd/1
option writes the HTTP status line (e.g. HTTP/1.1 200 OK
) and response headers to standard output (i.e. the console). The --dump-header
option dumps the headers to the given file. /dev/fd/1
is the file descriptor for stdout, so anything written to it is output to the console (or to wherever the standard output is piped or redirected).
-D, --dump-header <filename> (HTTP FTP) Write the received protocol headers to the specified file.
The --silent
option makes it so that just the headers are output, and not the progress bar.
-s, --silent 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.
The result of curl
is piped to tail command tail -n +2
, which discards the first line of content, which is the HTTP status line (e.g. HTTP/1.1 200 OK
). If you want or don't mind having the status line as well as the headers, this tail
pipe portion can be omitted.
-n, --lines=[+]NUM output the last NUM lines, instead of the last 10; or use -n +NUM to output starting with line NUM
$ curl http://www.example.com --output test.html \
--dump-header /dev/fd/1 --silent | tail -n +2
Age: 466166
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Wed, 27 Oct 2021 16:49:42 GMT
Etag: "3147526947+gzip+ident"
Expires: Wed, 03 Nov 2021 16:49:42 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (chb/0286)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1256
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With