How to format a Get Request

I have an external server running MySQL. I have installed a php script that, when accessed from HTTP will deliver data from one of the tables. It works fine from a browser:

I cannot figure out how to send this command from Arduino. I have the EthernetClient library working and can access Google as in the example.

When I send this command through the client:

client.println("//GET /php/getEvents.php HTTP/1.0");

the server returns:

<h1>Method Not Implemented</h1>
<p>GET to /php/getEvents.php not supported.

What is the correct way to format a GET in Arduino?

I use a GET to send a temperature to my web server. Note the lack of HTTP version and the additional blank line after the get - not sure whether the difference is important but it works:

void  SendTempToServer()
char GetRequest[80];
if (client.connect(server, 80))
  sprintf(GetRequest,"GET /cgi-bin/Arduino.cgi?Reading=%s&arduino_id=23&sensor_id=1",Temperature);

Do not use the double slash preceding the GET.

// change this
client.println("//GET /php/getEvents.php HTTP/1.0");
// to this
client.println("GET /php/getEvents.php HTTP/1.0");

And your web host uses virtual hosting. Insure you send the Host parameter. I use HTTP/1.1 for that.

client.println("GET /php/getEvents.php HTTP/1.1");
client.println("Connection: close\r\n");

Cool - That does work. Thank you very much. One last. Where can I go to learn why it works? Do you have a good reference or a Google subject I can read? Thanks again.

The correct format on the GET line is important for obvious reasons. The virtual server is a bit more obscure. Here is a wiki article on virtual hosting. A Google search works good for that if you need more info.

Cool again surfer. It looks like I have to go learn about HTTP Headers - Right?

Right, and the ability to recognize a virtual server so you know what header parameters are required. :slight_smile:

Here is how I determined your server uses virtual hosting. In the address bar of your browser
and you get your home page.

In nslookup

C:\Documents and Settings\user>nslookup

Non-authoritative answer:

Then try that ip in your web browser
You will get your web hosting service page

Surfer - learning a lot but one last and then I'll go away and study. I also have on that same server a php script that sets the database. It can be called from a browser like this:

What is the equivalent code for the arduino to do this?

client.println("GET /php/getEvents.php?pixel_ID=1212 HTTP/1.1");
client.println("Connection: close\r\n");

Here is my client code. I use a character array to pass the page and those parameters like this:


    if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));

Sweet. 8)


As you explained, after getting the hosting service page, how to get the header parameter i have to pass ?