Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
brha_3994521
Level 3
Level 3
First like received First like given

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

0 Likes
1 Solution
ChMa_3922746
Level 5
Level 5
10 likes received 10 likes given 5 likes given

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 */

...

View solution in original post

0 Likes
1 Reply
ChMa_3922746
Level 5
Level 5
10 likes received 10 likes given 5 likes given

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 */

...

0 Likes