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.
client? The class type of that is likely to have methods to help parse the post. Please provide a complete minimal verifiable example.readhere=okstarts after an empty line - maybe start with finding an empty line in a string first - POST values will be on the next line, right??str_tokandstr_sepand I reciving casting error:cannot convert 'String' to 'char*' for argument '1' to 'char* strtok(char*, const char*)'Stringis not the same aschar *. Callc_str()to convert String to a C string.char *requestString = request.c_str();Then you can usestrtrokand other C string functions.