Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling POST data from AJAX 2.4.0-rc2 #3791

Closed
kapyaar opened this issue Nov 3, 2017 · 3 comments
Closed

Handling POST data from AJAX 2.4.0-rc2 #3791

kapyaar opened this issue Nov 3, 2017 · 3 comments
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.

Comments

@kapyaar
Copy link

kapyaar commented Nov 3, 2017

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
@devyte
Copy link
Collaborator

devyte commented Nov 12, 2017

@kapyaar does PR #3313 fix this?

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Nov 12, 2017
@kapyaar
Copy link
Author

kapyaar commented Nov 18, 2017

@devyte YEs, that looks like it. Parsing first, and then decoding should solve this! If I update the cores using staging, is this update available now?

@devyte
Copy link
Collaborator

devyte commented Dec 30, 2017

Closing via #3313 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests

2 participants