difference in the use of get, http 1.0 and 1.1

Hello. I have a simple program that uses the ethernet shield. The code use the method GET in this way:

client.print("GET /myPage.php?parameter=147 HTTP/1.1");    
client.println("Host: www.eeteam.net");

If I use HTTP/1.1 I obtain the following error:

400 Bad Request

Bad Request

Your browser sent a request that this server could not understand.

if i use HTTP 1.0

client.print("GET /myPage.php?parameter=147 HTTP/1.0");    
//client.println("Host: www.eeteam.net");

I have no error but I can’t specify the host name.
Do you know why with HTTP1.1 the server say it is a bad request?
Thanks in advance

Do you know why with HTTP1.1 the server say it is a bad request?

Because the server is running some pretty old code that doesn't understand the HTTP 1.1 protocol.

It understands both. I was just checking the server with my ethernet shield, and it does fine on HTTP/1.0 and HTTP/1.1. This loads the home page, but it sends a redirect message.

// this works
client.println("GET / HTTP/1.1\r\nHost: www.eeteam.net\r\n");
// and this
client.println("GET / HTTP/1.0\r\nHost: www.eeteam.net\r\n");

The myPage.php file does not exist, and that will throw an error.

thanks SurferTim! your code works because after HTTP/1.1 or 1.0 you have a \r\n. My code was wrong becuse it hasn't. If I put a println (not a print), it works with both versions!

You are welcome! :slight_smile:

If you wondered why I coded that GET send the way I did, the reason is the number of packets required to send the request. This is the normal example:

// this is one packet
client.println("GET / HTTP/1.0");
// this is a second packet
client.println("Host: www.eeteam.net");
// and this is the third packet

This is one packet:

client.println("GET / HTTP/1.0\r\nHost: www.eeteam.net\r\n");

good explaination!

referring to http w3c protocol spec (RFC2616), http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html

at the end of each request line, you need a CRLF, then between the request line and message body, you need a blank line CRLF.

it has nothing to do with packet.

sending client.println("GET / HTTP/1.0\r\nHost: www.eeteam.net\r\n\r\n"); would work just fine and complies with http protocol specs.

it has nothing to do with packet.

Every time you call client.write(), client.print() or client.println(), it sends a packet. One call, one packet. Three calls, three packets.

you are implying because client.println("GET / HTTP/1.0\r\nHost: www.eeteam.net\r\n\r\n"); sends one packet, it won't work?

the w3c spec gives a more "authoritative" explanation on why sending the extra \r\n is needed. It has nothing to do with packets.

I see what you are saying. You are correct in that respect. It does not matter that the stuff arrives in one packet, or twenty. You can send it one character per packet. It will work. The empty line is the key.

But I like my stuff to work great. :)