Create a Web Server

Brattchess
Posts: 7
Joined: Mon Jul 16, 2018 6:04 am

Create a Web Server

Postby Brattchess » Thu Aug 30, 2018 3:16 pm

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

saden123
Posts: 12
Joined: Tue Jul 24, 2018 12:18 am

Re: Create a Web Server

Postby saden123 » Sun Sep 02, 2018 9:13 am

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.

Brattchess
Posts: 7
Joined: Mon Jul 16, 2018 6:04 am

Re: Create a Web Server

Postby Brattchess » Thu Sep 20, 2018 9:12 am

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

tommeyers
Posts: 184
Joined: Tue Apr 17, 2018 1:51 pm
Location: Santiago, Dominican Republic

Re: Create a Web Server

Postby tommeyers » Thu Sep 20, 2018 3:14 pm

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>\
     
IT Professional, Maker
Santiago, Dominican Republic

Who is online

Users browsing this forum: Bing [Bot] and 241 guests