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.

HTTPCli_sendRequest error

Other Parts Discussed in Thread: CC3200SDK

Hi all.

I am using the CC3200LAUNCHXL.

I invoke function "HTTPPostMethod" every 1 second.

When the count is 100, the function "HTTPCli_sendRequest" in "HTTPPostMethod" return -103.

Help me please.

  • Hi Kim,


    Can you please make sure server is not closing the connection.


    Regards,
    Aashish
  • Yes, the server is not closing.
    It occur the error, every 100th.
  • Hi Kim,

    Is it possible to share some example code with your server to reproduce this at our end.

    Regards,

    Aashish

  • Hi Aashish.

    while(1) {
    	osi_MsgQRead(&g_NetQueue, &RecvQue, OSI_WAIT_FOREVER);
    	if(PUB_MOTOR1_STATUS == RecvQue) {
    		static int count=0;
    		lRetVal = HTTPPostMethod(&httpClient[HTTPCLI_SENDACT1], SENDACT1);
    		if(lRetVal < 0)
    		{
    			UART_PRINT("HTTP Container Post failed.\n\r");
    		}
    		UART_PRINT("%s : count(%d)\n\r", __FUNCTION__, ++count);
    	}
    }

    I am waiting the message "PUB_MOTOR1_STATUS".
    And if I get the message, invoke the function "HTTPPostMethod".

    If you need more infomation, reply please.

    Regares,
    Gwanyoung Kim.
  • Hi Aashish.

    I tested by other way.

    I used "GET" method to restful test site "http://resttesttest.com/".

    And I imported the example source "http_client_demo".

    I changed some sources as follows,

    #define HOST_NAME        "httpbin.org"
    #define HOST_PORT           80
    static int HTTPGetMethod(HTTPCli_Handle httpClient) { long lRetVal = 0; HTTPCli_Field fields[2] = { {HTTPCli_FIELD_NAME_HOST, HOST_NAME}, {NULL, NULL} }; bool moreFlags; /* Set request header fields to be send for HTTP request. */ HTTPCli_setRequestFields(httpClient, fields); /* Send GET method request. */ /* Here we are setting moreFlags = 0 as there are no more header fields need to send at later stage. Please refer HTTP Library API documentaion @ HTTPCli_sendRequest for more information. */ moreFlags = 0; lRetVal = HTTPCli_sendRequest(httpClient, HTTPCli_METHOD_GET, "/get", moreFlags); if(lRetVal < 0) { UART_PRINT("Failed to send HTTP GET request.\n\r"); return lRetVal; } lRetVal = readResponse(httpClient); return lRetVal; } int main() { long lRetVal = -1; HTTPCli_Struct httpClient; // // Board Initialization // BoardInit(); // // Configure the pinmux settings for the peripherals exercised // PinMuxConfig(); // // Configuring UART // InitTerm(); // // Display banner // DisplayBanner(APP_NAME); InitializeAppVariables(); lRetVal = ConnectToAP(); if(lRetVal < 0) { LOOP_FOREVER(); } lRetVal = ConnectToHTTPServer(&httpClient); if(lRetVal < 0) { LOOP_FOREVER(); } while(1) { int cnt; static int count=0; cnt = 3000000; while(cnt) { cnt--; } UART_PRINT("\n\r"); UART_PRINT("HTTP Get Begin:\n\r"); lRetVal = HTTPGetMethod(&httpClient); if(lRetVal < 0) { UART_PRINT("HTTP Post Get failed.\n\r"); } UART_PRINT("HTTP Get End [%d]:\n\r", count++); UART_PRINT("\n\r"); if(count >= 100) count = 0; // Stop the CC3200 device LOOP_FOREVER(); }

    I used SDK version "CC3200SDK_1.1.0".

    This source also occur error at 100th request.

    Check please.

    Regards,

    Gwanyoung Kim.

  • Hi Kim,


    As suspected server closing the connection after 99th request. Refer HTTP response field "connection: close" of 99th request below. For all other request server responding with keep-alive in connection header.

    HTTP Get Begin:
    HTTP/1.1 200 OK
    Server: nginx
    Date: Wed, 14 Oct 2015 14:01:02 GMT
    Content-Type: application/json
    Content-Length: 131
    Connection: keep-alive
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Credentials: true

    {
    "args": {},
    "headers": {
    "Host": "httpbin.org"
    },
    "origin": "117.209.206.29",
    "url": "http://httpbin.org/get"
    }
    Successfully parsed 11 JSON tokens
    HTTP Get End [98]:


    HTTP Get Begin:
    HTTP/1.1 200 OK
    Server: nginx
    Date: Wed, 14 Oct 2015 14:01:03 GMT
    Content-Type: application/json
    Content-Length: 131
    Connection: close
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Credentials: true

    {
    "args": {},
    "headers": {
    "Host": "httpbin.org"
    },
    "origin": "117.209.206.29",
    "url": "http://httpbin.org/get"
    }
    Successfully parsed 11 JSON tokens
    HTTP Get End [99]:



    Regards,
    Aashish
  • Hi Aashish

    Thank you for your advice.

    By the way, must I again connect  to a http server whenever I request a Restful method?

    Regards,

    Gwanyoung Kim.

  • Hi Kim,

    Yes you need to re-initiate all steps once you get "connection:close" header filed from server.

    Regards,

    Aashish