OK had the same thing myself and took a while to figure out.
I can't find a way to send multiple lines in the request when using s_client interactively. It always sends the request immediately as soon as you've entered the first line. If someone knows how to get around this then please let me know!
Edit: I see Wei He has posted the way to do this - use the -crlf
flag but leaving this answer here as an alternative method.
In the meantime, as jww suggested, you have to use echo
for this:
echo -e "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" | openssl s_client ...
The next issue is that by default openssl closes the connection when the input file closes. Which is does immediately when using echo
like this. So you don't get time to see the response and instead just see the DONE output! :-(
You can add a sleep
to the echo command to get around this (note the brackets are important):
(echo -e "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"; sleep 10) | openssl s_client ...
Or, better than that, you can use the -ign_eof
option to leave the connection open:
echo -e "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" | openssl s_client -ign_eof ...
Or better yet, if you're only concerned with the HTTP responses then use the -quiet
option which hides most of the TLS noise and also sets that -ign_eof option for you:
echo -e "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" | openssl s_client -quiet ...
echo
:echo -e "GET / HTTP/1.1\r\nHost: example.com.br\r\n\r\n" | openssl s_client ...
. The\r\n
is significant because that's what the HTTP standard says to do. Two CRLF pairs at the end of the request is also significant because that's what the standard says to do. Also see How do you pipe “echo” into “openssl”?GET /index.html ...
or you may need to set a cookie. You should probably try withcurl
orwget
, and post the full request and response, including the error. Otherwise, you have to provide a real server name and URL so we can run the tests.