Go Down

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

James-Brown

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]
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:
Code: [Select]
client.println("//GET /php/getEvents.php HTTP/1.0");
the server returns:
Code: [Select]
</head><body>
<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?

wildbill

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


SurferTim

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");

Watch for me on National Geographic Wild "When Sharks Attack: Gulf Coast Killers". Airs on June 22nd.

James-Brown

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.

SurferTim

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.
Watch for me on National Geographic Wild "When Sharks Attack: Gulf Coast Killers". Airs on June 22nd.

James-Brown

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

SurferTim

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
http://www.seti.net
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
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
inmotionhosting.com
Watch for me on National Geographic Wild "When Sharks Attack: Gulf Coast Killers". Airs on June 22nd.

James-Brown

#7
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]
http://www.seti.net/php/setEvent.php?pixel_ID=1212
What is the equivalent code for the arduino to do this?

SurferTim

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.
http://playground.arduino.cc/Code/WebClient
I use a character array to pass the page and those parameters like this:
Code: [Select]
    sprintf(pageAdd,"/php/getEvents.php?pixel_ID=%u",totalCount);

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

Watch for me on National Geographic Wild "When Sharks Attack: Gulf Coast Killers". Airs on June 22nd.


hegdekir

Surfer,

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

Kiran

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!

Arduino
via Egeo 16
Torino, 10131
Italy