The WebServer class found in ESP8266WebServer.h
header, is a simple web server that knows how to handle HTTP requests such as GET and POST and can only support one simultaneous client.
ESP8266WebServer server(80);
Creates the ESP8266WebServer class object.
Parameters:
host IP address: IPaddress addr
(optional)
host port number: int port
(default is the standard HTTP port 80)
void begin();
void handleClient();
void close();
void stop();
Both methods function the same
void on();
void addHandler();
void onNotFound();
void onFileUpload();
Example:
server.on("/", handlerFunction);
server.onNotFound(handlerFunction); // called when handler is not assigned
server.onFileUpload(handlerFunction); // handle file uploads
void send();
void send_P();
Parameters:
code
- HTTP response code, can be 200
or 404
, etc.
content_type
- HTTP content type, like "text/plain"
or "image/png"
, etc.
content
- actual content body
const String & arg();
const String & argName();
int args();
bool hasArg();
arg
- get request argument value
argName
- get request argument name
args
- get arguments count
hasArg
- check if argument exist
const String & header();
const String & headerName();
const String & hostHeader();
int headers();
bool hasHeader();
header
- get request header value
headerName
- get request header name
hostHeader
- get request host header if available, else empty string
headers
- get header count
hasHeader
- check if header exist
bool authenticate();
void requestAuthentication();
authenticate
- server authentication, returns true if client is authenticated else false
requestAuthentication
- sends authentication failure response to the client
Example Usage:
if(!server.authenticate(username, password)){
server.requestAuthentication();
}
const String & uri(); // get the current uri
HTTPMethod method(); // get the current method
WiFiClient client(); // get the current client
HTTPUpload & upload(); // get the current upload
void setContentLength(); // set content length
void sendHeader(); // send HTTP header
void sendContent(); // send content
void sendContent_P();
void collectHeaders(); // set the request headers to collect
void serveStatic();
size_t streamFile();
For code samples enter here .