HTTP request (C/WinSock) What am I doing wrong?

Hi all,

I am having trouble understanding why my HTTP request is not working properly.  Basically, I connect to a server on port 80, and send the following request:
"GET / HTTP/1.1\r\n"
and then I get nothing.  However, if I send the erroneous request:
"GET HTTP/1.1\r\n"
I get the expected response "HTTP/1.1 400 Bad Request ..."

Am I missing something?  I have tried various combinations of extra request headers with no luck.  Pointers/tips/useful websites are all appreciated!!

Thanks in advance to any expert!
LVL 2
zechisAsked:
Who is Participating?
 
robpittConnect With a Mentor Commented:
The data sent must terminate with a double CRLF i.e. \r\n\r\n

The correct thing to send for HTTP1.1 is:
 "GET /webpage.htm HTTP/1.1\r\nHost: www.thewebsite.com\r\n\r\n"

Note that the above ends in double CRLF.
The Host: line is mandatory for HTTP1.1

Rob
0
 
zechisAuthor Commented:
I am ever grateful!!

Quick question though, how did you find this out?  I read RFC 2068 backwards and forwards and don't remember seeing the double CRLF anywhere!
0
 
robpittCommented:
It's all in there honest :-)
See section 4.1 Message Types - first couple of paragraphs.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.