Pages: [1]   Go Down
Author Topic: difference in the use of get, http 1.0 and 1.1  (Read 1019 times)
0 Members and 1 Guest are viewing this topic.
italy
Offline Offline
Full Member
***
Karma: 3
Posts: 223
Muuuuu
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello. I have a simple program that uses the ethernet shield. The code use the method GET in this way:
Code:
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:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>

if i use HTTP 1.0
Code:
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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Code:
// 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.
Logged

italy
Offline Offline
Full Member
***
Karma: 3
Posts: 223
Muuuuu
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are welcome!  smiley

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:
Code:
// 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
client.println();

This is one packet:
Code:
client.println("GET / HTTP/1.0\r\nHost: www.eeteam.net\r\n");
Logged

italy
Offline Offline
Full Member
***
Karma: 3
Posts: 223
Muuuuu
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

good explaination!
Logged

SF Bay area
Offline Offline
Sr. Member
****
Karma: 3
Posts: 268
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

SF Bay area
Offline Offline
Sr. Member
****
Karma: 3
Posts: 268
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley
Logged

Pages: [1]   Go Up
Jump to: