Solved

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

Posted on 2001-09-13
3
1,280 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 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

20 Experts available now in Live!

Get 1:1 Help Now