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:

http://www.seti.net/php/getEvents.php

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:

</head><body>
<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);
  //Serial.println(GetRequest);
  client.println(GetRequest);
  client.println();
  }
}

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("Host: www.seti.net");
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. http://en.wikipedia.org/wiki/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
http://www.seti.net
and you get your home page.

In nslookup

C:\Documents and Settings\user>nslookup www.seti.net
Server:  ip68-105-28-16.at.at.cox.net
Address:  68.105.28.16

Non-authoritative answer:
Name:    seti.net
Address:  205.134.250.170
Aliases:  www.seti.net

Then try that ip in your web browser
http://205.134.250.170
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:

http://www.seti.net/php/setEvent.php?pixel_ID=1212

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("Host: www.seti.net");
client.println("Connection: close\r\n");

Here is my client code. http://playground.arduino.cc/Code/WebClient I use a character array to pass the page and those parameters like this:

    sprintf(pageAdd,"/php/getEvents.php?pixel_ID=%u",totalCount);

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

Sweet. 8)

Surfer,

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

Kiran