This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220SF-LAUNCHXL: CC3220SF HTTP POST failed NOT able to POST on the LOCAL webserver

Part Number: CC3220SF-LAUNCHXL
Other Parts Discussed in Thread: CC3220SF

hello Sir/Madam,

                            I am working on my sample project which require to post some sensor data on my local webserver. 

i have gone through the Http get example which is working very fine and i am getting response through http get method.

but i want to post some data same way on my local webserver but i am not able to post the data in json format.

i am able to successfully connect with my local webserver with cc3220 and getting status code 200 also but my server only getting empty flower brackets no data in that.

any help is appriciated, below is my code snippet.

void* httpTask(void* pvParameters)
{
    bool moreDataFlag = false;
    char data[HTTP_MIN_RECV];
    int16_t ret = 0;
    int16_t len = 0;

    /* Print Application name */
    DisplayBanner(APPLICATION_NAME);

    sem_wait(&ipEventSyncObj);
    Display_printf(display, 0, 0, "Sending a HTTP GET request to '%s'\n",
            HOSTNAME);

    HTTPClient_Handle httpClientHandle;
    int16_t statusCode;

    //HTTP POST method
    const char header[] = "Basic dZdDpXGVz0N0";
    httpClientHandle = HTTPClient_create(&statusCode, 0);
    if (statusCode < 0)
    {
        printError("httpTask: creation of http client handle failed", statusCode);
    }

    ret = HTTPClient_setHeader(httpClientHandle, HTTPClient_HFIELD_REQ_USER_AGENT, USER_AGENT, strlen(USER_AGENT), HTTPClient_HFIELD_PERSISTENT);
    ret |= HTTPClient_setHeader(httpClientHandle, HTTPClient_HFIELD_REQ_AUTHORIZATION, (const char *)header, strlen((const char *)header), HTTPClient_HFIELD_PERSISTENT);
    ret |= HTTPClient_setHeader(httpClientHandle, HTTPClient_HFIELD_REQ_CONTENT_TYPE, (const char *)"application/json", strlen((const char *)"application/json"), HTTPClient_HFIELD_PERSISTENT);
    if (ret < 0) {
        printError("httpTask: setting request header failed", ret);
    }

    ret = HTTPClient_connect(httpClientHandle, HOSTNAME1, 0, 0);
    if (ret < 0) {
        printError("httpTask: connect failed", ret);
    }
    ret = HTTPClient_sendRequest(httpClientHandle, HTTP_METHOD_POST, POST_REQUEST_URI, (const char *)"{\"Name\":\"Kaushik\"}", strlen((const char *)"{\"Name\":\"Kaushik\"}"), 0);
    if (ret < 0) {
        printError("httpTask: send failed", ret);
    }

    if (ret != HTTP_SC_OK) {
        printError("httpTask: cannot get status", ret);
    }

    Display_printf(display, 0, 0, "HTTP Response Status Code: %d\n", ret);

    len = 0;
    do {
        ret = HTTPClient_readResponseBody(httpClientHandle, data, sizeof(data), &moreDataFlag);
        if (ret < 0) {
            printError("httpTask: response body processing failed", ret);
        }
        Display_printf(display, 0, 0, "%.*s \r\n",ret ,data);
        len += ret;
    }while (moreDataFlag);

    Display_printf(display, 0, 0, "Received %d bytes of payload\n", len);

    ret = HTTPClient_disconnect(httpClientHandle);
    if (ret < 0)
    {
        printError("httpTask: disconnect failed", ret);
    }

    HTTPClient_destroy(httpClientHandle);

    return(0);
}

Can any one please tell me where i am doing wrong?

Am i setting any wrong header fields or need to set any further header field....?

below is my macros

#define HOSTNAME1              "http://192.168.2.131:3010"
#define POST_REQUEST_URI      "/post_data"
#define USER_AGENT            "HTTPClient (ARM; TI-RTOS)"

please help me i am stuck here and not able to proceed further

Thanks.

  • Hi Kaushik,

    When you run your program with the debugger and step through the execution of HTTPClient_sendRequest(), do you see that the POST data is passed in correctly? If you completely step through that function, you should eventually get to the underlying sl_Send() call on the TCP socket to your HTTP server. In the send buffer, do you see the JSON data that you are expecting?

    Regards,
    Michael
  • Hi Michael,

    i Run my program through debugger step by step and gone through execution of programs HTTPClient_sendRequest(), i can see post data in sume string , but not able to see in send buff, and i didnt come across any sl_send() call here. So what can i do here, am i doing something wrong here or what.....? please let me know.........
  • Hi Kaushik,

    If you step into HTTPClient_sendRequest(), you'll see that it constructs the HTTP request and then sends it using a SlNetSock_send() call. This call is implemented through a sl_Send() call, but for our debugging purposes let's assume that SlNetSock_send() works so that we don't need to go deeper in the call stack.

    When you look at cli->validBufStart, as well as the bytesToSend variable, do they look correct? On your server side, are you able to run wireshark to check the raw HTTP request and see if the server gets the correct data?

    Regards,
    Michael
  • Hi, Michael 

    As you told i have checked values of bytes to Send variables and as well as cli->validBufStart looks ok bytes to send value i am getting 18 exactly equals the payload length.

    on pc where webserver is running i ran some wireshark tests and analyze packets also. in packet headers are there as well as length and data also able to see

    in packet, but one doubt is first headers will send and after payload will be sending from board in different packets, is it correct? or it should be like both headers and payload both should go in single packets. please let me know i am attaching belo my wireshark packet frame here please see it.

  • hi Michael,

    i have uploaded packet images of wireshark here, packet sequence is from 23-27,
    please note that last image is for full packet capture here where you can see the packet sequence .


    packet 23- contains tcp headers,
    packet 24- contains payload,
    packet 25- ACK,
    packet 26- continuation (this packet is doubt ful it contains only .. kind of things which i am not sending no clue where its appending)
    packet 27 - contains response of my webserver which should be reply me back same json payload which i am sending but in data its giving me back only empty brackets.

    please let me know if you have solutions regarding this. its good if you provide me HTTP post examples also.

    one weired thing i noted is, i am successfully able to post on http://httpbin.org/post website
    and its giving me a valid response also, but with my local webserver its not working...
    dont have any clue..

    Any help is appreciated...
  • Hi Kaushik,

    TCP packet fragmentation is something that will need to be supported by your HTTP server. If you can see the expected HTTP request data within wireshark on the PC side, then the CC3220 HTTP library is working as intended. This is especially true if you can successfully POST to other web servers.

    Please take a look at your server and debug why it is not seeing the POST data. You'll probably want to check to see if there is some component that needs configuration or updating to better handle fragmented TCP packets.

    Let me know if you need further clarification or help.

    Regards,
    Michael
  • Hi Michael it will be good if you provide some HTTP Post example for CC3220SF Board that will help to me.....
    i will try with some another web server and see weather it will resolve or not...?
    Thanks
  • Hi Kaushik,

    A HTTP POST example for the CC3220 does not exist, so I am unable to provide you with the exact code to perform this HTTP POST request. However, if you are getting the correct data on the PC side as observed in wireshark, then you are already invoking the HTTP library on the CC3220 correctly.

    Regards,
    Michael