Page 1 of 1

How to handle <form> data received by http server e.g (key=value&key=value&key=value&…) using C language?

Posted: Tue Jan 15, 2019 1:42 am
by Alsaber
I have http server running on esp32. It serves a short html web page that contains a form. Once I fill the form and click submit using POST method, I receive the form values as follows:
Key1=value1&Key2=value2&Key3=value3&...
The whole data received is saved as a string inside a buffer.

The question is: how can I handle this data by saving each key=vale in a variable so it it can be later saved in the NVS flash? e.g:

Code: Select all

int key1 = value1
int key2 = value2 
int key3 = value3
I am using ESP-IDF and C language

Thank you very much

Re: How to handle <form> data received by http server e.g (key=value&key=value&key=value&…) using C language?

Posted: Fri Sep 24, 2021 11:29 am
by nopnop2002

Re: How to handle <form> data received by http server e.g (key=value&key=value&key=value&…) using C language?

Posted: Fri Sep 24, 2021 8:22 pm
by mbratch
It's just a C string parsing exercise, and there are a few different reasonable ways to do it. You could parse the string using strtok to get the key-value pairs. You could then parse the values from the keys using "strtok" again if you wanted to, inside of your loop that processes the pairs. You may have to further convert your value to the type you want it to be if not a string. Once you have a string key and a value, you can call the NVS API to write it.

Re: How to handle <form> data received by http server e.g (key=value&key=value&key=value&…) using C language?

Posted: Fri Sep 24, 2021 10:08 pm
by chegewara