In the browser that works fine, the data gets stored. But I want to call the code from an Arduino. I'm using fairly boiler plate code adapted from the Arduino wifi library sample:
But the response I get back from the server is: HTTP Error 400. The request verb is invalid. If I try HEAD or POST instead of GET I still receive the same error. If I miss out the payload and just use this code:
Don't spot the problem, but you could construct the string and then print it over the serial port so that you can double-check that the c string escaping you've done has produced the URL you intended. Can you enable logging on your web server, or capture the traffic in a packet sniffer, to see what was actually sent?
If you type the URL directly into the browser address field, that would result in an HTTP Get so I suggest you use a GET for your testing.
Can you check what the page address is after you submit the URL manually? It may be that the browser has secretly URL-encoded some of the special characters such as :, [, ] in your URL.
The data transmission method for "post" and "get" request are different. Below is an example of a post type of transmission that was posted by others on the forum.
client.println("POST hxxp://yourdomain.com/SMSSite/XMLInterface/Postxml.aspx HTTP/1.0");
// add a header indicating you have content-data to send. If you set this too low, the server won't see it. If it is too high, the server may wait, or report an error.
client.print("content-length: ");
client.println(strlen(big_string));
// tell the server you are done with the header.
client.println();
// send the posted data.
client.print(big_string);
Thanks Peter & zoomkat, this now hurts my head. I rewrote my HTTP command to remove a few of the escaped quotation marks that the System.Web.Script.Serialization.JavaScriptSerializer in the ASP code did not require, and put the HTTP message in a separate line and sent it to the console (so that I could check my escaped quotation marks were correct). The string looks correct but, and this is the bit that makes my head hurt, the act of declaring the HTTP message separately makes it work! I.e. this code works: