1 Reply Latest reply on Feb 14, 2019 3:19 AM by ChMa_3922746

    Solution for HTTPS Client - Post messages to an Secure Server

    brha_3994521

      Anyone have recommendations or examples for the best method to post data over HTTPS to a server.  I can do an https get, but have not found an easy way to do a secure post.  Any suggestions would be appreciated. Simpler the better.

       

      Thanks

        • 1. Re: Solution for HTTPS Client - Post messages to an Secure Server
          ChMa_3922746

          I was just combing through the Cypress Academy files for other reasons, but getting POST working through an HTTPS client on the device to a remote Internet server may be of interest to me in the future.  Cypress Academy files are here:  GitHub - cypresssemiconductorco/CypressAcademy_WW101_Files

           

          In the folder /Cypress Academy WW101 Files /Projects/ww101key/07b/, you will see two examples:

          05_httpbin_post

          06_httpbin_post_tls

           

          It appears that the only delta between the GET and POST is the addition of the http_request_write to insert the message after the header:

           

          /* This is the JSON message that we will send */

          #define JSON_MSG           "{\"WICED\":\"yes\"}"

          ...

          /* Header 2 is the content length. In this case, it is the length of the JSON message */

              sprintf(json_len,"%d", strlen(JSON_MSG)); /* Calculate the length of the JSON message and store the value as a string */

              header[2].field        = HTTP_HEADER_CONTENT_LENGTH;

              header[2].field_length = strlen( HTTP_HEADER_CONTENT_LENGTH );

              header[2].value        = json_len; // This holds the length of the JSON message as a sting containing the decimal value

              header[2].value_length = strlen( json_len ); // This is the length of the string that holds the JSON message size. For example, if the JSON is 12 characters, this would be "2" because the string "12" is 2 characters long.

          ...

          http_request_write( &request, (uint8_t* ) JSON_MSG, strlen(JSON_MSG)); /* Write the content */

          ...