- Tue May 10, 2016 9:38 pm
#47271
The ESP8266WebServer library is included with the Arduino ESP8266 board package. The example program HelloServer has code to parse multiple arguments.
When the HelloServer code is running on an ESP, connect to
http://esp8266.local/q?temp=100.0&humidity=32.1The browser window should show something like this. This URL connects to a URL not handled by the web server because the handleNotFound() function conveniently prints out the arguments which confirms the library handles arguments correctly.
Code: Select allFile Not Found
URI: /q
Method: GET
Arguments: 2
temp: 100.0
humidity: 32.1
The following code in HelloServer.ino builds the response string.
Code: Select all String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
You can use the methods server.args(), server.argName(), and server.arg() in handleroot() to process URLs like this.
[url]http://esp8266.local/?temp=100.0&humidity=32.1
[/url]