-1

I was looking at Most straightforward way of getting a raw, unparsed HTTPS response to make a GET request to a url over HTTPS, and receive the raw, unparsed response.

the following works:

echo 'GET / HTTP/1.1
Host: google.com

' | openssl s_client -quiet -connect google.com:443 2>/dev/null

However, I want to put the request in a text file and cat it to the command.

So I created raw-http.txt

GET / HTTP/1.0
Host: google.com    

Just to be clear, there is a blank like after Host: google.com.

Now when I try:

cat raw-http.txt | openssl s_client -quiet -connect google.com:443 2>/dev/null

it just freezes for a long time then respond ^X%.

why echo is working here but cat not. what can I do about this?

Ahmad Ismail
  • 2,478
  • 1
  • 22
  • 47

1 Answers1

2

there is a blank like after

There should be two.

$ echo '"'; cat raw.txt; echo '"'
"
GET / HTTP/1.0
Host: google.com    

"
$ cat raw.txt | openssl s_client -quiet -connect google.com:443 2>/dev/null
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>

As for your echo example it has an extra unneeded newline, so this will work:

echo 'GET / HTTP/1.1
Host: google.com
' | openssl s_client -quiet -connect google.com:443 2>/dev/null
Artem S. Tashkinov
  • 26,392
  • 4
  • 33
  • 64