@@ -146,6 +146,34 @@ Tested on ESP32-S2 Feather.
146146 :emphasize-lines: 25-27,39,51,60,66
147147 :linenos:
148148
149+ Form data parsing
150+ ---------------------
151+
152+ Another way to pass data to the handler function is to use form data.
153+ Remember that it is only possible to use it with ``POST `` method.
154+ `More about POST method. <https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST >`_
155+
156+ It is important to use correct ``enctype ``, depending on the type of data you want to send.
157+
158+ - ``application/x-www-form-urlencoded `` - For sending simple text data without any special characters including spaces.
159+ If you use it, values will be automatically parsed as strings, but special characters will be URL encoded
160+ e.g. ``"Hello World! ^-$%" `` will be saved as ``"Hello+World%21+%5E-%24%25" ``
161+ - ``multipart/form-data `` - For sending text and binary files and/or text data with special characters
162+ When used, values will **not ** be automatically parsed as strings, they will stay as bytes instead.
163+ e.g. ``"Hello World! ^-$%" `` will be saved as ``b'Hello World! ^-$%' ``, which can be decoded using ``.decode() `` method.
164+ - ``text/plain `` - For sending text data with special characters.
165+ If used, values will be automatically parsed as strings, including special characters, emojis etc.
166+ e.g. ``"Hello World! ^-$%" `` will be saved as ``"Hello World! ^-$%" ``, this is the **recommended ** option.
167+
168+ If you pass multiple values with the same name, they will be saved as a list, that can be accessed using ``request.data.get_list() ``.
169+ Even if there is only one value, it will still get a list, and if there multiple values, but you use ``request.data.get() `` it will
170+ return only the first one.
171+
172+ .. literalinclude :: ../examples/httpserver_form_data.py
173+ :caption: examples/httpserver_form_data.py
174+ :emphasize-lines: 32,47,50
175+ :linenos:
176+
149177Chunked response
150178----------------
151179
0 commit comments