Page 1 of 1

Create a Web Server

Posted: Thu Aug 30, 2018 3:16 pm
by Brattchess
Hello,

I would like to know which is the best example for start to program a web server?
Where is possible to find it?
Thanks in advance.

Best Regards,
Juan

Re: Create a Web Server

Posted: Sun Sep 02, 2018 9:13 am
by saden123
I'm using a libeshttpd fork for my projects https://github.com/chmorgan/libesphttpd

Also: the ESP-IDF has an http server component, example here https://github.com/espressif/esp-idf/tr ... ttp_server - I haven't used it yet but it looks pretty good.

Re: Create a Web Server

Posted: Thu Sep 20, 2018 9:12 am
by Brattchess
Hello,

I am starting from the example of the http_server of ESP-IDF.

But I detect that when the server sends a response always put the:
Content-Type application/json

What can I do to remove it?

Best regards,
Juan

Re: Create a Web Server

Posted: Thu Sep 20, 2018 3:14 pm
by tommeyers
From my esp32 web server:

Code: Select all

#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>


server.on("/update", HTTP_GET,
                [](AsyncWebServerRequest *request){
                  Serial.println(">>>>>>>>>>update");
                  int paramsNr = request->params();
                  Serial.print(" Number of Parameters: ");
                  Serial.println(paramsNr);
                  for(int i=0;i<paramsNr;i++){
                      AsyncWebParameter* p = request->getParam(i);
                      Serial.print("Param name: ");
                      Serial.print(p->name());
                      Serial.print("  Param value: ");
                      Serial.println(p->value());
                      String name = p->name();
                      String value = p->value();
                      Serial.println(">>>>>>>>>>>>>>>" + name + "/" + value);
                      preferencesUpdate(name, value);
                  }
                  request->send(200, "text/html", createHTML());
                }
      );
      server.begin();
      Serial.println(" Started");
      return true;
    }
    //============================================================================================
    static String createHTML() {
      String tempHTML;
      tempHTML = (String) "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\
           <html>\
             <head width=100% align=center>\
                <title width=100% align=center>ESP32 - Preferences</title>\