Skip to content

Handling POST data from AJAX 2.4.0-rc2 #3791

Closed
@kapyaar

Description

@kapyaar

Basic Infos

Hardware

Hardware: ESP-12
Core Version: 2.4.0-rc2

Description

I have an html form that inputs SSID and Password and submits to ESP using ajax. To handle special characters in ssid and or passwords (especially "&"), I would encode the String before submitting it. In 2.3.0, it was working ok. But Trying to upgrade to 2.4.0-rc2, I have a problem.

In my ajax, I did not have any "Content-Type" Set. This leads to the ESP 2.4.0-rc2 spitting the POST Data as "Plain", and unparsed.

So I tried

xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

Now, the data gets parsed, but then comes trouble. Say my post data looks like this.

ssid=his&herWiFi&password=her&hisPassword

I encode just the SSID and Password before sending, so it looks like
ssid=his%26herWiFi&password=her%26hisPassword

But now on the ESP, server.arg("ssid") gives "his", and password gives "her" as it cuts off after the "&"

I also tried
xmlhttp.setRequestHeader("Content-Type", "multipart/form-data");

But that leads to some boundary error messages during parsing.

Any Idea on how to handle this situation?

Settings in IDE

Module: ?Generic ESP8266 Module?
Flash Size: 4MB/1MB
CPU Frequency: 80Mhz
Flash Mode: qio
Flash Frequency: 40Mhz
Upload Using: SERIAL
Reset Method: nodemcu

Sketch

for ( uint8_t i = 0; i < server.args(); i++ ) {
        if (server.argName(i) == "ssid") {
          DEBUG_PRINT("Got RAW SSID ");
          DEBUG_PRINT(server.arg("ssid"));
          //ssid = urldecode(server.arg("ssid"));//Does not seem to need decoding.
          ssid = server.arg("ssid").c_str();;
        }
        if (server.argName(i) == "password") {
          DEBUG_PRINT(" and pass: ");
          DEBUG_PRINTLN(server.arg(i));
          //pass     = urldecode(server.arg(i)).c_str();;//Does not seem to need decoding.
          pass     = server.arg(i).c_str();
        }
      }

Debug Messages

messages here

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting for feedbackWaiting on additional info. If it's not received, the issue may be closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions