Solved

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

Posted on 2001-09-13
3
1,282 Views
Last Modified: 2013-12-03
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
Comment
Question by:zechis
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
robpitt earned 300 total points
ID: 6480721
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
 
LVL 2

Author Comment

by:zechis
ID: 6480912
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
 
LVL 5

Expert Comment

by:robpitt
ID: 6481849
It's all in there honest :-)
See section 4.1 Message Types - first couple of paragraphs.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now