0

I'm trying to extract POST fields data from this:

POST / HTTP/1.1
Host: 192.168.4.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 54
Origin: http://192.168.4.1
Connection: keep-alive
Referer: http://192.168.4.1/
Upgrade-Insecure-Requests: 1

readHere=ok&ssidName=Itziks+Home&ssidPassword=123456789

The variable request hold the whole message:

WiFiClient client = server.available();
String request = client.readString();
Serial.println(request);

WifiClient documentation: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/client-class.html

I've tried to split it with strtok() like this and I get an convert error:

WiFiClient client = server.available();
String request = client.readString();
String req = strtok(request,'\r');
Serial.println(req);

And this is the error:

cannot convert 'String' to 'char*' for argument '1' to 'char* strtok(char*, const char*)'

I can't really think of a practical way to doing this. Thank for the help.

6
  • What is client? The class type of that is likely to have methods to help parse the post. Please provide a complete minimal verifiable example. Commented Feb 22, 2021 at 20:29
  • Do you know how to extract anything from a string? How to "tokenize" a string? What research did you do? The readhere=ok starts after an empty line - maybe start with finding an empty line in a string first - POST values will be on the next line, right?? Commented Feb 22, 2021 at 20:30
  • @kaylum, I've added the details about client class please refresh, thanks! Commented Feb 22, 2021 at 20:37
  • @KamilCuk, I've tried with str_tok and str_sep and I reciving casting error: cannot convert 'String' to 'char*' for argument '1' to 'char* strtok(char*, const char*)' Commented Feb 22, 2021 at 20:39
  • String is not the same as char *. Call c_str() to convert String to a C string. char *requestString = request.c_str(); Then you can use strtrok and other C string functions. Commented Feb 22, 2021 at 20:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.