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.

Error with POST Request from Tiva C Board

Other Parts Discussed in Thread: TM4C1294NCPDT, SYSBIOS

I am using TM4C1294NCPDT on EK-1294XL board. tirtos_tivac_2_14_04_3, TivaWare_C_Series-2.1.2.111, CCS_6.1.2.00015 versions.
I have taken HTTP GET example code from TI-RTOS and trying to send POST Request to local server. Following is the code snippet I have modified(code is attached in zip file):

ret = HTTPCli_sendRequest(&cli, HTTPStd_POST, REQUEST_URI, true);
if (ret < 0) {
System_printf("httpTask: send failed1111:%d", ret);
}
else{
ret = HTTPCli_sendRequestBody(&cli, POST_REQ_DATA, sizeof(POST_REQ_DATA));
if (ret < 0) {
System_printf("httpTask: send failed12222:%d", ret);
}
}
ret = HTTPCli_getResponseStatus(&cli);
if (ret != HTTPStd_OK) {
System_printf("httpTask: cannot get status:%d", ret);
}

In this code HTTPCli_getResponseStatus() is always returning 400 error. GET request is working fine and giving correct response. Reason on Server is showing that No content to map to Object due to end of input it means Request is reaching as empty to server.
Do anybody have idea what is wrong with code or how to send POST_REQ_DATA along with header parameters as JSON? Following is the request format to be sent:

POST /app/api/data/post HTTP/1.1
Host: 192.168.0.102
Authentication: Basic
Content-Type: application/json

{"ss":"true"}

Also this code is running once whenever IP is assigned. How to run this code to send POST request at regular intervals?

Thanks,
Bhavesh

2068.POC_Socket_POST.zip

  • I'll try to reproduce the problem. If you have WireShark, can you capture the packets and attach the file?

    Regarding the regular interval, you can use create a ti.sysbios.knl.Clock object that runs at some periodic interval.

    Todd

  • Hi Todd,

    Sorry but network policies within my premise does not allow to capture Network log files so cannot run WireShark. You can test this POST request on any of available site which allows it.

    About regular interval, will check and revert back.

    Thanks,
    Bhavesh
  • Also one more thing is I want to send large payload of around 25Kbytes in one Request.
    I am trying to set large value SEND_BUFLEN in tirtos_tivac\packages\ti\net\http\httpcli.c to 24576 and than creating library again.
    And whenever it is trying to send GET or POST request it is generating exception at ti_sysbios_family_arm_m3_Hwi_excHandlerAsm__I(). And in ROV exception is shown in Hwi
    Less than or equal to 8192 is working fine.
    How to send large payload with POST request in this case? 

    Thanks,
    Bhavesh

  • Is this a separate question or additional information for the first issue?
  • Hi Todd,

    This is the additional information for the issue reported earlier.

    To local server we have created one GET API which is sending large chunk of data in response and one POST request which takes non JSON standard request as input.

    In GET service response, response size is around 16KBytes and it is generating error as mentioned earlier. In GET response if size is less than 8192 bytes it is working fine.

    As POC for POST serivce we created a Non Standard JSON as below, it is able to send 8192 bytes but if I increase size more than that it is creating error. 

    POST 192.168.0.102/.../stringpost HTTP/1.1
    Host: 192.168.0.102
    Authentication: Basic

  • Hi Bhavesh,

    Regarding issue 1 - POST error code:

    HTTP 400 request generally means the request could not be understood by the server due to malformed syntax. The request format that you posted doesn't contain "Content-Length" field. Is the application sending this field? This is required for POST method requests as the server needs to know length of data that has to be read.

    Regarding issue 2 - large payloads:

    You don't need to modify SEND_BUFLEN and rebuild the library. Instead, I would suggest sending the data in smaller batches by calling HTTPCli_sendRequestBody() multiple times. As I mentioned above, the server would be waiting for the data of length as set in the "Content-Length" field.

    For ex, you can send data of smaller lengths as shown below:

    count = sizeof(POST_REQ_DATA);
    dataSize = 64;
    offset = 0;
    while(count > 0) {
     
        if (count < dataSize) {
             dataSize = count;
        }    
        ret = HTTPCli_sendRequestBody(&cli, POST_REQ_DATA + offset,  dataSize);
        //do error check
    
        count -= dataSize;
        offset += dataSize;
    }

    Regarding issue 3 - exception:

    I think the Task stack is not sufficient. Please check the value of your Task stack. Since you are allocating large local buffers of size greater than the Task stack (which probably is 8K), this exception is being generated.

    Hope this helps,

    Vikram

  • Is the issue resolved? If yes, please mark this thread as answered or closed.

    Vikram
  • Hi Vikram,

    Sorry for late reply but I still not have checked suggestion you have provided and it will take time for me to check as facing issues with other things.

    We can close this thread and if no solution found than will open another thread.

    Thank you for information.

    Thanks,
    Bhavesh

  • OK. I will close this thread.

    Vikram