Using strok
This commit is contained in:
@@ -47,18 +47,16 @@ void setup() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
EthernetClient client = server.available();
|
EthernetClient client = server.available();
|
||||||
if (client) {
|
if (client) {
|
||||||
String res = client.readString();
|
String res = client.readStringUntil('\n');
|
||||||
String params[3];
|
int str_len = res.length() + 1;
|
||||||
int index = 0;
|
char char_array[str_len];
|
||||||
int start = 0;
|
res.toCharArray(char_array, str_len);
|
||||||
for (int i = 0; i < 3; i++) {
|
char* method = strtok(char_array, " ");
|
||||||
index = res.indexOf(' ', index);
|
char* path = strtok(0, " ");
|
||||||
params[i] = res.substring(start, index);
|
Serial.println(method);
|
||||||
start = index;
|
Serial.println(path);
|
||||||
index++;
|
|
||||||
}
|
|
||||||
if (client.available()) {
|
if (client.available()) {
|
||||||
if (params[0] != "GET") {
|
if (method != "GET") {
|
||||||
sendMethodNotAllowed(client);
|
sendMethodNotAllowed(client);
|
||||||
} else {
|
} else {
|
||||||
sendHeaders(client);
|
sendHeaders(client);
|
||||||
Reference in New Issue
Block a user