httpUnauthorized()

Description

Return HTTP error 401. This will cause web browsers to prompt for username and password.

Syntax

webserver.httpUnauthorized();

Parameters

None

Returns

None

Examples

#include "WebServer.h"

WebServer webserver; // defaults to no prefix, port 80

void privateCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) {
  if (server.checkCredentials("YWRtaW46YWRtaW4=")) { // admin:admin in base64 is YWRtaW46YWRtaW4=
    server.httpSuccess();
    P(helloMsg) = "<h1>Hello Admin</h1>";
    server.printP(helloMsg);
  } else {
    server.httpUnauthorized();
  }
}

void setup() {
  // Ethernet stuff here, e.g. set MAC and IP address
  webserver.addCommand("private.html", &privateCmd);
  webserver.begin();
}

void loop() {
  webserver.processConnection();
}

« back to Webduino

Reply

Your email address will not be published. Required fields are marked *