Tool/software: Code Composer Studio
Dear Sir,
I have an question about the Internal HTTP server of the CC3220 device. i am following the out box example for the my reference. as i see in example there have a post and get method to the device here also i need a post and get method for the getting information and configuring the device.
Here i am able to run the get method as expected with response but while POST method i am able to get the payload but i could not able to send response back to client with application/json.
Here i am using preparing metadata as per the outbox example and too send them am using @sl_NetAppSend API as per explain in the example.
I need a response when i do post method but i could not regenerate .
Please do needful .
Here my example to send a response
uint16_t prepareGetMetadata(int32_t parsingStatus, uint32_t contentLen, HttpContentTypeList contentTypeId)
{
char *contentType;
uint8_t *pMetadata;
uint16_t metadataLen;
contentType = g_ContentTypes[contentTypeId].contentTypeText;
memset((uint8_t*)&gMetadataBuffer, 0x00, sizeof(gMetadataBuffer));
pMetadata = gMetadataBuffer;
/* http status */
*pMetadata = (uint8_t) SL_NETAPP_REQUEST_METADATA_TYPE_STATUS;
pMetadata++;
*(uint16_t*) pMetadata = (uint16_t) 2;
pMetadata += 2;
if (parsingStatus < 0)
{
*(uint16_t*) pMetadata = (uint16_t) SL_NETAPP_HTTP_RESPONSE_404_NOT_FOUND;
}
else
{
*(uint16_t*) pMetadata = (uint16_t) SL_NETAPP_HTTP_RESPONSE_200_OK;
}
pMetadata += 2;
/* Content type */
*pMetadata = (uint8_t) SL_NETAPP_REQUEST_METADATA_TYPE_HTTP_CONTENT_TYPE;
pMetadata++;
(*(uint16_t*) pMetadata) = (uint16_t) strlen((const char*) contentType);
pMetadata += 2;
sl_Memcpy(pMetadata, contentType, strlen((const char* )contentType));
pMetadata += strlen((const char*) contentType);
/* Content len */
*pMetadata = SL_NETAPP_REQUEST_METADATA_TYPE_HTTP_CONTENT_LEN;
pMetadata++;
*(uint16_t*) pMetadata = (uint16_t) 4;
pMetadata += 2;
*(uint32_t*) pMetadata = (uint32_t) contentLen;
metadataLen = 5 + 7 + strlen((const char*) contentType) + 3;
return (metadataLen);
}
uint16_t preparePostMetadata(int32_t parsingStatus)
{
uint8_t *pMetadata;
uint16_t metadataLen;
memset((uint8_t*)&gMetadataBuffer, 0x00, sizeof(gMetadataBuffer));
pMetadata = gMetadataBuffer;
/* http status */
*pMetadata = (uint8_t) SL_NETAPP_REQUEST_METADATA_TYPE_STATUS;
pMetadata++;
*(uint16_t *)pMetadata = (uint16_t) 2;
pMetadata += 2;
if(parsingStatus < 0)
{
*(uint16_t *)pMetadata = (uint16_t) SL_NETAPP_HTTP_RESPONSE_404_NOT_FOUND;
}
else
{
/* no need for content so browser stays on the same page */
*(uint16_t *)pMetadata = SL_NETAPP_HTTP_RESPONSE_200_OK; //(uint16_t) SL_NETAPP_HTTP_RESPONSE_204_OK_NO_CONTENT;
}
pMetadata += 2;
metadataLen = 5;
return(metadataLen);
}
//if payload created
if(status > 0)
{
//get the payload length
len = strlen((const char*)gPayloadBuffer);
if (netAppRequest->Type == SL_NETAPP_REQUEST_HTTP_GET)
{
metadataLen = prepareGetMetadata(0, len, HttpContentTypeList_ApplicationJson);
}
else
{
metadataLen = preparePostMetadata(status);
}
sl_NetAppSend(netAppRequest->Handle, metadataLen, gMetadataBuffer, (SL_NETAPP_REQUEST_RESPONSE_FLAGS_CONTINUATION | SL_NETAPP_REQUEST_RESPONSE_FLAGS_METADATA));
/* mark as last segment */
sl_NetAppSend(netAppRequest->Handle, len, gPayloadBuffer, 0);
WMLogInfo(DEBUG_LOG, "Payload buffer sent with %d", len);
}