6

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.

Colonel Panic
  • 132,665
  • 89
  • 401
  • 465

3 Answers3

6

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
Jonas Kongslund
  • 5,058
  • 2
  • 28
  • 27
yellowcap
  • 3,985
  • 38
  • 51
2

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.

Jakub Roztocil
  • 15,930
  • 5
  • 50
  • 52
1

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
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465