I happen to be writing a very simple text browser, and I'm having a problem connecting to servers using HTTP1.1 GET messages... HTTP1.0 works fine, I just have a string like this:

const char *request = "GET / HTTP/1.0\n\n";

This works great, and I receive my html back from the host just fine. But when I change it to a HTTP1.1 request, I get nothing back...

//  Assuming that I'm connecting to google...
const char *request = "GET / HTTP/1.1\nHost: www.google.com\n"

Any ideas as to why I'm not getting anything back from the server?

-Fredric

Hmm, perhaps you need another newline all by itself?

Try

//  Assuming that I'm connecting to google...
const char *request = "GET / HTTP/1.1\nHost: www.google.com\n\n"

That doesn't seem to work, although it should. I have no idea what's going on, I think I'll just have to settle with HTTP1.0...

-Fredric

this should work:
const char *request = "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n"

http protocol uses \r\n as a new line, and the last line must always be empty.

I put the \r in there, and I started getting data from the server!

Thanks. :)

-Fredric

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.