Form Processing
Your application will likely need to accept data from the user. Forms allow you to do just that. Forms can be submitted in one of two methods (GET and POST), and this server supports both.
The GET method appends the data to the end of the URI. You'll see this
data following the question mark (?) in your browser's address bar. For Microchip's
embedded server, this data is limited to around 80 bytes. However, this sort of
submission is generally easier to process. Data sent via GET is automatically
decoded, and stored in the array curHTTP.data
. Your application will
handle the data in the HTTPExecuteGet
callback. The functions
HTTPGetArg
and HTTPGetROMArg
provide an easy
method to retrieve submitted values for processing.
As an example, this GET form controls several LEDs on the demo board:
Exercise: Modify this form to support LED 5.
The POST method submits the data after the request headers are sent. This allows the data to be virtually unlimited in length, as long as your application can process it in chunks. However, your application must manage the receipt of data, so it is generally more complicated.
Data sent via POST is left in the TCP buffer for your application to retrieve as
it is ready. The callback HTTPExecutePost
will be called repeatedly
until your callback returns HTTP_IO_DONE
. Your application should
use the TCPFind
and TCPGet
functions to retrieve data
from the buffer. If you return HTTP_IO_NEED_DATA
the server will
execute your callback again later when the buffer has been filled again.
As an example, this POST form sets the text shown on the LCD display: