首页 > 解决方案 > 使用C从http请求中提取post值

问题描述

我正在尝试从中提取 POST 字段数据:

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

该变量request包含整个消息:

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

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

我试图strtok()像这样拆分它,但出现转换错误:

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

这是错误:

无法将参数 '1' 的 'String' 转换为 'char*' 到 'char* strtok(c​​har*, const char*)'

我真的想不出一个实用的方法来做到这一点。感谢您的帮助。

标签: carduino-esp8266esp8266wifi

解决方案


推荐阅读