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.

Unable to retrieve message body for a GET method on MSP430F5529LP/CC3100 (Http_Client example)

Part Number: CC3100BOOST
Other Parts Discussed in Thread: CC3100

I have being working on developing a IOT project using MSP430F5529LP and CC3100. Currently is I am unable to retrieve the response body from a message response to GET method request. I have executed the same GET Method command using CURL and I get a complete response include both the Header and Body. Below is the curl command.

curl -k -v "www.example.com/.../userLogin

Below is excerpt from the response

* STATE: INIT => CONNECT handle 0x6000572f0; line 1103 (connection #-5000)

* TLSv1.2 (OUT), TLS header, Certificate Status (22):


> User-Agent: curl/7.47.0
> Accept: */*

* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 200 OK
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Content-Type: application/xml;charset=UTF-8
< Transfer-Encoding: chunked
< Vary: Accept-Encoding
< Date: Sat, 09 Sep 2017 12:33:41 GMT
< Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
< Cache-Control: private, max-age=0, no-cache, no-store
<
* STATE: PERFORM => DONE handle 0x6000572f0; line 1645 (connection #0)
* Curl_done
* Connection #0 to host www.example.com left intact

<ns1:userLoginResponse xmlns:ns1="example.com/.../ns1:userLoginResponse>

Following information can be retrieved. `Server, Content-Type, Transfer-Encoding: chunked, Vary, Date, Strict-Transport-Security and Cache-Control` but I am unable to retrieve `<ns1:userLoginResponse xmlns:ns1="example.com/.../ns1:userLoginResponse>`

I have modified http_client example I believe the issue is related to GET method not returning a "Content-Length"

I believe in the following code the variable `len` is looking for a value greater than 0.

bytesRead = HTTPCli_readResponseBody(httpClient, (char *)dataBuffer, len, &moreFlags);

The variable `len` is set by the following code

case 0: /* HTTPCli_FIELD_NAME_CONTENT_LENGTH */
{
len = strtoul((char *)g_buff, NULL, 0);
}

Since `"Content-Length"` is not present in the GET method response header the value remains the initial value of 0.

I am hope someone has encountered a similar scenario if so can you please share some ideas how this issue can be resolved.

Reference:

  • Hi Mahendra,

    There are a total of 4 posts of this topic in the forum. We shall continue the discussion in this thread.

    Thanks.

    Sincerely,
    Bryan Kahler
  • Hi Mahendra,

    When the server uses Transfer-encoding: chunked, as in your example response above, the Content-Length header is not utilized because the length is unknown at the time of initial transmission.

    What version of SDK are you using?

    What modifications have your made to the http_client example?

    What does your error output look like?

    Are you receiving a retVal of -118?

    Sincerely,

    Bryan Kahler

  • Hello Bryan,

    Thank you for responding.


    What version of SDK are you using?

    CC3100 1.2 SDK version, CC3100 service pack version 1.0.1.6-2.7.0.0


    What modifications have your made to the http_client example?

    I have made changes to implement TLS/Security

    I also have made the following changes to readResponse(HTTPCli_Handle httpClient) function for debugging and code understanding purposes 

    switch(id)
    	{
    		case 0: /* HTTPCli_FIELD_NAME_CONTENT_LENGTH */
    		{
    			len = strtoul((char *)g_buff, NULL, 0);
    		}
    		break;
    		case 1: /* HTTPCli_FIELD_NAME_CONNECTION */
    		{
    		}
    		break;
    		case 2: /* HTTPCli_FIELD_NAME_CONTENT_TYPE */
    		{
    			if(!strncmp((const char *)g_buff, "application/json",sizeof("application/json")))
    			{
    				json = 1;
    				xml = 0;
    				CLI_Write(" ");
    				CLI_Write(HTTPCli_FIELD_NAME_CONTENT_TYPE);
    				CLI_Write(" : ");
    				CLI_Write("application/json\n\r");
    			}
    			else if (!strncmp((const char *)g_buff, "application/xml",sizeof("application/xml")))
    			{
    				json = 0;
    				xml=1;
    				CLI_Write(" ");
    				CLI_Write(HTTPCli_FIELD_NAME_CONTENT_TYPE);
    				CLI_Write(" : ");
    				CLI_Write("application/xml\n\r");
    			}
    			else
    			{
    				/* Note:
                                    Developers are advised to use appropriate
                                    content handler. In this example all content
                                    type other than json are treated as plain text.
    				 */
    				json = 0;
    				xml = 0;
    
    				CLI_Write(" ");
    				CLI_Write(HTTPCli_FIELD_NAME_CONTENT_TYPE);
    				CLI_Write(" : ");
    				CLI_Write("Not determined \n\r");
    			}
    		}
    		break;
    		case 3: /* HTTPCli_FIELD_NAME_VARY */
    		{
    				CLI_Write(" Wrong filter id\n\r");
    		}
    		break;
    		case 4: /* HTTPCli_FIELD_NAME_DATE */
    		{
    				CLI_Write(" Wrong filter id\n\r");
    		}
    		break;
    		case 5: /* HTTPCli_FIELD_NAME_CACHE_CONTROL */
    		{
    				CLI_Write(" Wrong filter id\n\r");
    		}
    		break;
    		case 6: /* HTTPCli_FIELD_NAME_TRANSFER_ENCODING */
    		{
    			CLI_Write(" HTTPCli_FIELD_NAME_TRANSFER_ENCODING\n\r");
    		}
    		break;
                    default:
    		{
    				CLI_Write(" Wrong filter id\n\r");
    				retVal = -1;
    				goto end;
    		}
    	}


    What does your error output look like?

    I don't get any errors? The body of the message variable is empty

    bytesRead = HTTPCli_readResponseBody(httpClient, (char *)dataBuffer, len, &moreFlags);

    The dataBuffer variable is empty after executing the above line of code in readResponse(HTTPCli_Handle httpClient) function 

    Also I have observed that state variable from cli data structure is 4 and flag variable is 4. 

    As a result the following code inside HTTPCli_readResponseBody(HTTPCli_Handle cli, char *body, int len, bool *moreFlag) function gets executed. But I think since len=0, the content in body variable is empty.

        if (getCliState(cli, CHUNKED_FLAG)) {
            ret = getChunkedData(cli, body, len, moreFlag);
        }

    Based on my research (Chunked transfer encoding) and your comment "Transfer-encoding: chunked" might have some relevance.


    I also believe that getChunkedData function from httpcli.c might have some relevance too.  

    /*
     *  ======== getChunkedData ========
     *  Get chunked transfer encoded data
     */
    static int getChunkedData(HTTPCli_Handle cli, char *body, int len, bool *moreFlag)

    Thank you

    Mahendra

  • Hi Mahendra,

    Is the request being properly received and processed at the server? Please try your request against a server under your control and record the response sent from the server to the device.

    Sincerely,
    Bryan Kahler