1

I am trying to have my arduino run a web server but also post a variable from time to time. I have the following code:

client.println("HTTP/1.1 200 OK");
client.println("Host: joeybabcock.me");    //
client.print("GET /writetemplocalserv.php?t0=");     
client.println("Content-Type: text/html");
client.println(sensorValue);
client.println("Connnection: close");

and the whole code here(It's quite a bit so only look through if you have to.): http://pastebin.com/TXPccYs3 This does not post the variable. if visited in the web browser to the exact same url, it does, however, work.

2
  • Is this a request or a response??? This is not valid HTTP. Read RFC2161 before throwing bytes to network. Commented Nov 26, 2013 at 10:14
  • i need to submit a get request at the brginning of the program, than a standard response when a client connects. i have the standard response, just not the get request Commented Nov 26, 2013 at 15:04

1 Answer 1

3

RFC 2161, defining /1.1, MUST always be followed when writing Web (HTTP) servers and clients.

Your code is a big mess:

client.println("HTTP/1.1 200 OK"); //Response
client.println("Host: joeybabcock.me"); //Response/request
client.print("GET /writetemplocalserv.php?t0="); //Request
client.println("Content-Type: text/html"); //Response
client.println(sensorValue); //Probably invalid...
client.println("Connnection: close"); //Request/Response

In a very, VERY, VERY brief way, if you want to request you do:

client.print("GET /writetemplocalserv.php?t0=");
client.print(sensorValue);
client.println(" HTTP/1.1");
client.println("Host: joeybabcock.me");
client.println(""); //mandatory blank line

For responses:

client.println("HTTP/1.1 200 OK");
client.println("Host: joeybabcock.me");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("");
client.println("body data");
...

Again, any HTTP request/response must follow RFC 2161!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I was not able to find any documentation on this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.