Ok, here's my arduino code:
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 30 };
byte server[] = { 192, 168, 1, 31 };
Client client(server, 80);
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
client.println("GET /script.php?getdata=1");
client.println(" HTTP/1.1");
client.println("Host: 192.168.1.31");
client.println();
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
}
Here's my php code:
<html>
<?php
if ($_GET[getdata] == "1") {
echo "it works";
} else {
echo "no var";
}
?>
</html>
When I run that, on the arduino console i get 400 - Bad request.
However if, in a web browser I do
http://192.168.1.31/script.php?getdata=1
I get the output expected. What am I doing wrong?