Cookies

Microchip TCP/IP Stack

Microchip TCP/IP Stack Help
Cookies

Overview 

This section describes how to use the cookie demo in the TCP/IP Demo App HTTP2 demo. For information about how to implement cookies in your own page, see the HTTP2 Cookies topic

Instructions 

  1. Program your board with the demo code and upload the demo app web page. Open your web browser and navigate to the board's web page (http://mchpboard by default).
  2. Navigate to the Cookies page using the navigation panel on the left of the page.
  3. Type your first name into the "First Name" text box and click "Set Cookies." Verify that the name was read successfully and displayed in the "Name" output field.

 

 

Exercise 

You can optionally complete the exercise described on the "Cookies" page. In this exercise, you will create a cookie called "fav" with the value in the favorite field in the example box. You may want to read the HTTP2 dynamic variable, GET, and cookie topics first.

  1. Start by opening cookies.htm in your "TCPIP Demo App\WebPages2" folder.
  2. Locate the code for the example box that displays the name and favorite PIC architecture. Replace the "not implemented" string with a dynamic variable to output the data from the cookie.
  3. Locate the code for the select box form input for the favorite architecture. Note the value of the name field of the select form.
  4. Open CustomHTTPApp.c in the TCP/IP Demo App MPLAB project. Locate the HTTPExecuteGet function and find the code that handles GET method inputs from cookies.htm.
  5. Set the value of curHTTP.hasArgs to indicate that two form arguments are present in the data buffer.
  6. In CustomHTTPApp.c, create a function to output data for the dynamic variable you created in step 2. The name of the function will depend on the name of the variable. For a variable named ~cookiefavorite~ you would implement a function called HTTPPrint_cookiefavorite. This function should search through the curHTTP.data data buffer to try and find a name/value pair with the name equal to the name of your select form from step 3. If it finds it, it should write the value for that pair to the TCP buffer; otherwise, it should write "not set." See the implementation of HTTPPrint_cookiename for an example.
void HTTPPrint_cookiename(void)
{
    BYTE *ptr;

    ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE*)"name");

    if(ptr)
        TCPPutString(sktHTTP, ptr);
    else
        TCPPutROMString(sktHTTP, (ROM BYTE*)"not set");

    return;
}
  1. Compile your web page using the MPFS2 Utility and upload it to your board. You may receive a warning that your dynamic variables have changed in your page.
  2. Rebuild your project and program your board.
  3. Verify that both cookies can be set.
Module
Microchip TCP/IP Stack 5.42.08 - June 15, 2013
Copyright © 2012 Microchip Technology, Inc.  All rights reserved.