user71205: I have a function for HTTP_POST responses but it is never called when I post to it. I get the webpage instead.
I call on it with
server.on("/",HTTP_POST,response);

But I only get the url in response.
void setup() {
    pinMode(led_pin, OUTPUT);

    Serial.begin(115200);
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_USB) || defined(SERIAL_PORT_USBVIRTUAL)
    delay(2000); // To be able to connect Serial monitor after reset and before first printout
#endif
    // Just to know which program is running on my Arduino
    Serial.println(F("START " __FILE__ " from " __DATE__));
    Serial.print(F("Ready to send IR signals at pin "));
    Serial.println(IR_SEND_PIN);

    pinMode(led_pin, OUTPUT);
    digitalWrite(led_pin, 0);
    Serial.begin(115200);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    Serial.println("");

    // Wait for connection
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }

    Serial.println("");
    Serial.print("Connected to ");
    Serial.println(ssid);
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());

    if (MDNS.begin("esp32")) {
      Serial.println("MDNS responder started");
    }

    server.on("/", handleRoot);
    server.on("/test.svg", drawGraph);
    server.on("/",HTTP_POST,response);
    server.on("/inline", []() {
    server.send(200, "text/plain", "this works as well");
    });
    server.onNotFound(handleNotFound);
    server.begin();
    Serial.println("HTTP server started");

}



void response(){
  //int khz = 38; // 38kHz carrier frequency for the NEC protocol
  
  if(server.hasArg("on") && (server.arg("on").length()>0)){ // TODO check that it's not longer than 31 characters
      Serial.print("Server was turned on:\t");
      Serial.println(server.arg("on"));

      ++CYCLE0;
      server.sendHeader("Location", String("/"), true); //how to do a redirect, next two lines
      server.send ( 302, "text/plain", "");
  } else if (server.hasArg("off") && (server.arg("off").length()>0)){
      Serial.print("Server was turned off:\t");
      Serial.println(server.arg("off"));

      ++CYCLE1;
      server.sendHeader("Location", String("/"), true);
      server.send ( 302, "text/plain", "");

   } else if (server.hasArg("up") && (server.arg("up").length()>0)){
      Serial.print("Server temp was turned up:\t");
      Serial.println(server.arg("up"));

      ++CYCLE2;
      server.sendHeader("Location", String("/"), true);
      server.send ( 302, "text/plain", "");

  } else if (server.hasArg("down") && (server.arg("down").length()>0)){
      Serial.print("Server temp was turned down:\t");
      Serial.println(server.arg("down"));

      ++CYCLE3;
      server.sendHeader("Location", String("/"), true);
      server.send ( 302, "text/plain", "");
  
  } else {
    server.send(400, "text/html", "<html><body><h1>HTTP Error 400</h1><p>Bad request. Please enter a value.</p></body></html>");
  }
}

How do you get an http post response back instead of a webpage?
POST response:
<html>

<head>
    <meta http-equiv='refresh' content='5' />
    <title>ESP32 Demo</title>
    <style>
        body {
            background-color: #cccccc;
            font-family: Arial, Helvetica, Sans-Serif;
            Color: #000088;
        }
    </style>
</head>

<body>
    <h1>Hello from ESP32!</h1>
    <p>Uptime: 00:05:32</p> <img src="/test.svg" />
    <h2>Turn air condistioner on</h2>
    <p>AC has been cycled 0 times</p>
    <form name='frm0' method='post'> <input type='text' name='on' value=8000>
        <input type='submit' value='Submit'>     </form>
        <p>Turn air conditioner off 0 times</p>
        <form name='frm1' method='post'> <input type='text' name='off' value=8000>
            <input type='submit' value='Submit'>     </form>
            <p>Turn temperature up 0 times</p>
            <form name='frm2' method='post'> <input type='text' name='up' value=8000>
                <input type='submit' value='Submit'>     </form>
                <p>Turn temperature down 0 times</p>
                <form name='frm3' method='post'> <input type='text' name='down' value=8000>
                    <input type='submit' value='Submit'>     </form>
</body>

</html>

Complete code
long version

user70020: You have:
server.on("/", handleRoot);
server.on("/test.svg", drawGraph);
server.on("/",HTTP_POST,response);

The first call using handleRoot species no particular method, and in this case it seems any method is acceptable.  You later specify server.on("/",HTTP_POST,response); specifically for POST requests.  These are added to a request handler list in the order given.  And apparently consulted in the order given.
In short, you need to specify HTTP_GET for handleRoot or just specify your HTTP_POST for response first and let handleRoot catch non-HTTP_POST requests afterwards:
server.on("/",HTTP_POST,response);
server.on("/", handleRoot);
server.on("/test.svg", drawGraph);


71205: <p>I have a function for HTTP_POST responses but it is never called when I post to it. I get the webpage instead.</p>
<p>I call on it with</p>
<pre><code>server.on(&quot;/&quot;,HTTP_POST,response);
</code></pre>
<p>But I only get the url in response.</p>
<pre><code>void setup() {
    pinMode(led_pin, OUTPUT);

    Serial.begin(115200);
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_USB) || defined(SERIAL_PORT_USBVIRTUAL)
    delay(2000); // To be able to connect Serial monitor after reset and before first printout
#endif
    // Just to know which program is running on my Arduino
    Serial.println(F(&quot;START &quot; __FILE__ &quot; from &quot; __DATE__));
    Serial.print(F(&quot;Ready to send IR signals at pin &quot;));
    Serial.println(IR_SEND_PIN);

    pinMode(led_pin, OUTPUT);
    digitalWrite(led_pin, 0);
    Serial.begin(115200);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    Serial.println(&quot;&quot;);

    // Wait for connection
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(&quot;.&quot;);
    }

    Serial.println(&quot;&quot;);
    Serial.print(&quot;Connected to &quot;);
    Serial.println(ssid);
    Serial.print(&quot;IP address: &quot;);
    Serial.println(WiFi.localIP());

    if (MDNS.begin(&quot;esp32&quot;)) {
      Serial.println(&quot;MDNS responder started&quot;);
    }

    server.on(&quot;/&quot;, handleRoot);
    server.on(&quot;/test.svg&quot;, drawGraph);
    server.on(&quot;/&quot;,HTTP_POST,response);
    server.on(&quot;/inline&quot;, []() {
    server.send(200, &quot;text/plain&quot;, &quot;this works as well&quot;);
    });
    server.onNotFound(handleNotFound);
    server.begin();
    Serial.println(&quot;HTTP server started&quot;);

}



void response(){
  //int khz = 38; // 38kHz carrier frequency for the NEC protocol
  
  if(server.hasArg(&quot;on&quot;) &amp;&amp; (server.arg(&quot;on&quot;).length()&gt;0)){ // TODO check that it's not longer than 31 characters
      Serial.print(&quot;Server was turned on:\t&quot;);
      Serial.println(server.arg(&quot;on&quot;));

      ++CYCLE0;
      server.sendHeader(&quot;Location&quot;, String(&quot;/&quot;), true); //how to do a redirect, next two lines
      server.send ( 302, &quot;text/plain&quot;, &quot;&quot;);
  } else if (server.hasArg(&quot;off&quot;) &amp;&amp; (server.arg(&quot;off&quot;).length()&gt;0)){
      Serial.print(&quot;Server was turned off:\t&quot;);
      Serial.println(server.arg(&quot;off&quot;));

      ++CYCLE1;
      server.sendHeader(&quot;Location&quot;, String(&quot;/&quot;), true);
      server.send ( 302, &quot;text/plain&quot;, &quot;&quot;);

   } else if (server.hasArg(&quot;up&quot;) &amp;&amp; (server.arg(&quot;up&quot;).length()&gt;0)){
      Serial.print(&quot;Server temp was turned up:\t&quot;);
      Serial.println(server.arg(&quot;up&quot;));

      ++CYCLE2;
      server.sendHeader(&quot;Location&quot;, String(&quot;/&quot;), true);
      server.send ( 302, &quot;text/plain&quot;, &quot;&quot;);

  } else if (server.hasArg(&quot;down&quot;) &amp;&amp; (server.arg(&quot;down&quot;).length()&gt;0)){
      Serial.print(&quot;Server temp was turned down:\t&quot;);
      Serial.println(server.arg(&quot;down&quot;));

      ++CYCLE3;
      server.sendHeader(&quot;Location&quot;, String(&quot;/&quot;), true);
      server.send ( 302, &quot;text/plain&quot;, &quot;&quot;);
  
  } else {
    server.send(400, &quot;text/html&quot;, &quot;&lt;html&gt;&lt;body&gt;&lt;h1&gt;HTTP Error 400&lt;/h1&gt;&lt;p&gt;Bad request. Please enter a value.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;);
  }
}
</code></pre>
<p>How do you get an http post response back instead of a webpage?</p>
<p>POST response:</p>
<pre><code>&lt;html&gt;

&lt;head&gt;
    &lt;meta http-equiv='refresh' content='5' /&gt;
    &lt;title&gt;ESP32 Demo&lt;/title&gt;
    &lt;style&gt;
        body {
            background-color: #cccccc;
            font-family: Arial, Helvetica, Sans-Serif;
            Color: #000088;
        }
    &lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;h1&gt;Hello from ESP32!&lt;/h1&gt;
    &lt;p&gt;Uptime: 00:05:32&lt;/p&gt; &lt;img src=&quot;/test.svg&quot; /&gt;
    &lt;h2&gt;Turn air condistioner on&lt;/h2&gt;
    &lt;p&gt;AC has been cycled 0 times&lt;/p&gt;
    &lt;form name='frm0' method='post'&gt; &lt;input type='text' name='on' value=8000&gt;
        &lt;input type='submit' value='Submit'&gt;     &lt;/form&gt;
        &lt;p&gt;Turn air conditioner off 0 times&lt;/p&gt;
        &lt;form name='frm1' method='post'&gt; &lt;input type='text' name='off' value=8000&gt;
            &lt;input type='submit' value='Submit'&gt;     &lt;/form&gt;
            &lt;p&gt;Turn temperature up 0 times&lt;/p&gt;
            &lt;form name='frm2' method='post'&gt; &lt;input type='text' name='up' value=8000&gt;
                &lt;input type='submit' value='Submit'&gt;     &lt;/form&gt;
                &lt;p&gt;Turn temperature down 0 times&lt;/p&gt;
                &lt;form name='frm3' method='post'&gt; &lt;input type='text' name='down' value=8000&gt;
                    &lt;input type='submit' value='Submit'&gt;     &lt;/form&gt;
&lt;/body&gt;

&lt;/html&gt;
</code></pre>
<p>Complete code</p>
<p><a href="https://bpa.st/HSTQO" rel="nofollow noreferrer">long version</a></p>
 70020: <p>You have:</p>
<pre class="lang-cpp prettyprint-override"><code>server.on(&quot;/&quot;, handleRoot);
server.on(&quot;/test.svg&quot;, drawGraph);
server.on(&quot;/&quot;,HTTP_POST,response);
</code></pre>
<p>The first call using <code>handleRoot</code> species no particular method, and in this case it seems <a href="https://github.com/espressif/arduino-esp32/blob/1.0.5-rc6/libraries/WebServer/src/WebServer.cpp#L250" rel="nofollow noreferrer">any method is acceptable</a>.  You later specify <code>server.on(&quot;/&quot;,HTTP_POST,response);</code> specifically for POST requests.  These are <a href="https://github.com/espressif/arduino-esp32/blob/1.0.5-rc6/libraries/WebServer/src/WebServer.cpp#L266" rel="nofollow noreferrer">added to a request handler list</a> in the order given.  And apparently <a href="https://github.com/espressif/arduino-esp32/blob/1.0.5-rc6/libraries/WebServer/src/Parsing.cpp#L116" rel="nofollow noreferrer">consulted</a> in the order given.</p>
<p>In short, you need to specify <code>HTTP_GET</code> for <code>handleRoot</code> or just specify your <code>HTTP_POST</code> for <code>response</code> first and let <code>handleRoot</code> catch non-<code>HTTP_POST</code> requests afterwards:</p>
<pre class="lang-cpp prettyprint-override"><code>server.on(&quot;/&quot;,HTTP_POST,response);
server.on(&quot;/&quot;, handleRoot);
server.on(&quot;/test.svg&quot;, drawGraph);
</code></pre>
