Colonel Panic
Colonel Panic

Reputation: 137732

How to print response headers to console and save content to file?

How can I print the response headers to console and save the response content to a file?


I tried

http GET http://download.sysinternals.com/files/SysinternalsSuite.zip --output sis.zip

But this printed both the headers and content to the file, making it nonsense.

Upvotes: 7

Views: 4430

Answers (3)

yellowcap
yellowcap

Reputation: 4021

It is possible in an updated version, the --output option will print the output into a file, and the --download option will make sure that the headers are print to the console, and only the content to the output file.

Here is an example:

http GET "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=Stack%20Overflow" --download --output bla.txt

Upvotes: 6

Colonel Panic
Colonel Panic

Reputation: 137732

It's not possible. Reported issue https://github.com/jkbr/httpie/issues/97

Update 2013: Fixed. Try

http -h --download http://download.sysinternals.com/files/SysinternalsSuite.zip

Upvotes: 1

Jakub Roztocil
Jakub Roztocil

Reputation: 16252

This is what HTTPie does by default:

So, the output depends on where it is being printed to. You can overwrite the default context-sensitive behaviour with one of the output options. For example, the following saves the headers as well as the body to a file:

http --output sis.zip --print=hb download.sysinternals.com/files/SysinternalsSuite.zip 

HTTPie currently doesn't allow outputing binary data to the terminal.

Upvotes: 2

Related Questions