I
I
Ilya Zimin2021-12-26 21:23:13
Arduino
Ilya Zimin, 2021-12-26 21:23:13

How to intercept all http requests on esp?

There is esp32 which works in the access point mode on which the server works.
And there is a task to process all requests coming from any url.
The question is how to process all PSOT|GET requests with one function, and in the function see which domain, url the request was made for?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Zimin, 2021-12-26
@Floket

It turned out to process all the urls, but now how can I find out the domain by which I changed it?

#include <WiFi.h>
#include <DNSServer.h>
#include <WebServer.h>

WebServer webServer(80);

const char *ssid = "TEST-123";
const char *password = NULL; // "12345678";

IPAddress apIP(192, 168, 1, 4);
DNSServer dnsServer;

void setup() {
  WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid, password);
  delay(100);
  
  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));

  const byte DNS_PORT = 53;
  dnsServer.start(DNS_PORT, "*", apIP);

webServer.onNotFound([]() {
    String message = "Hello World!\n\n";
    message += "URI: ";
    message += webServer.uri();
    Serial.println(webServer.hostHeader());
    webServer.send(200, "text/plain", message);
  });
  webServer.begin();
}

void loop() {
  dnsServer.processNextRequest();
  webServer.handleClient();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question