Go Down

Topic: How to format a Get Request (Read 973 times) previous topic - next topic


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:
Code: [Select]
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:
Code: [Select]
client.println("//GET /php/getEvents.php HTTP/1.0");
the server returns:
Code: [Select]
<h1>Method Not Implemented</h1>
<p>GET to /php/getEvents.php not supported.<br />

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:

Code: [Select]

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.
Code: [Select]
// 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.
Code: [Select]
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.
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.  :)

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
Code: [Select]
C:\Documents and Settings\user>nslookup www.seti.net
Server:  ip68-105-28-16.at.at.cox.net

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

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


Jun 22, 2013, 04:39 pm Last Edit: Jun 22, 2013, 04:46 pm by James-Brown Reason: 1
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:
Code: [Select]
What is the equivalent code for the arduino to do this?


Code: [Select]
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.
I use a character array to pass the page and those parameters like this:
Code: [Select]

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



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


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131