Jump to content
JINU

CC3200 https

Recommended Posts

Hi,

    In http client demo works fine ,when i POST data in  https got 400 error,can any suggest How to POST data in HTTPS.

   https post method works fine in energia ,but not in CCS ide ,below i added functions in the code

int connectToServer(HTTPCli_Handle httpClient)

{

    long retVal=-1;
    unsigned long g_ulDestinationIp=0;
    struct sockaddr_in addr;


    int    iAddrSize;


    if(cur_DestinationIP==0){

        retVal=sl_NetAppDnsGetHostByName((signed char *)HOST_NAME, strlen((const char *)HOST_NAME), &cur_DestinationIP, SL_AF_INET);
        if(retVal<0){
            Report("Ip fetch error \n\r");
            return -1;
        }
    }

    g_ulDestinationIp=cur_DestinationIP;
    struct HTTPCli_SecureParams sparams;
            /* Set secure TLS connection  */
            /* Security parameters */
            sparams.method.secureMethod = SL_SO_SEC_METHOD_SSLV3;
            sparams.mask.secureMask =SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA256 ; //SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA;
            strncpy(sparams.cafile, ROOTCA_PEM_FILE, strlen(ROOTCA_PEM_FILE));
            sparams.privkey[0] = 0;
            sparams.cert[0] = 0;
            sparams.dhkey[0] = 0;

            HTTPCli_setSecureParams(&sparams);
    //Report("fetched ip %d \n\r",g_ulDestinationIp);

    /* Set up the input parameters for HTTP Connection */
    addr.sin_family = SL_AF_INET;
    addr.sin_port = sl_Htons(HOST_PORT);
    addr.sin_addr.s_addr = sl_Htonl(g_ulDestinationIp);

    
    /* Testing HTTPCli open call: handle, address params only */
    HTTPCli_construct(httpClient);
    retVal = HTTPCli_connect(httpClient, (struct sockaddr *)&addr,0, NULL);
    if (retVal < 0)
    {
        Report("Connection failed !\n\r");
        return -1;
    }
   
    return 0;
}


int httpPost(HTTPCli_Handle httpClient,const char * requestURI,char * postData){

    char contLength[4];
    int postDataLen=strlen(postData);
    sprintf((char *)contLength, "%d",postDataLen);
    //sprintf((char *)contLength, "%d",(sizeof(postData)-1));

    HTTPCli_Field fields[6]={
                             {HTTPCli_FIELD_NAME_HOST, HOST_NAME},
                             {HTTPCli_FIELD_NAME_ACCEPT, "*/*"},
                             {HTTPCli_FIELD_NAME_CONNECTION,"close"},
                             {HTTPCli_FIELD_NAME_CONTENT_TYPE, "application/x-www-form-urlencoded"},
                             //{HTTPCli_FIELD_NAME_CONTENT_LENGTH, contLength},
                             {NULL, NULL}
    };

    HTTPCli_setRequestFields(httpClient, fields);
    HTTPCli_sendRequest(httpClient, HTTPCli_METHOD_POST, requestURI, 1);

    HTTPCli_sendField(httpClient, HTTPCli_FIELD_NAME_CONTENT_LENGTH, (const char *)contLength, 1);

    int rt=HTTPCli_sendRequestBody(httpClient, postData, postDataLen);

    return rt;
}

 

Edited by bluehash
[ADMIN] Please use code tags<> next time. Thank you!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×