• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1300
  • Last Modified:

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!
0
zechis
Asked:
zechis
  • 2
1 Solution
 
robpittCommented:
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

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now