C Program (using strstr function) equivalent of web_reg_save_param in loadrunner.

I had a situtaion in which I was not able to retrieve the session id from the resposne using web_reg_save_param function. The session id was available in resposne header.
So what I did is, captured the entire response header and from that I retrieved the session id using the Left & Right boundary via C Program. Pls find the code below.

char *CStr; //variable in which the response header will be saved
char *LB = "SMSESSION="; //Left Boundary of Session ID
char *RB = "; path"; //Right Boundary of Session ID
char *CorrParam = NULL; //variable in which Session ID will be saved
char *start, *end;

web_save_header(RESPONSE, "Input"); //LR function to capture the response header

/* login request */
web_submit_data("login",

lr_output_message("# Response Header:\n %s", lr_eval_string("{Input}")); //Print the response header
 
    CStr = (char *)calloc(8000000,sizeof(char));
 
   strcpy(CStr, lr_eval_string(lr_eval_string("{Input}"))); //Save it to the C variable

    if ( start = (char *)strstr( CStr, LB ) ) //Finds the first occurance of LB in CStr
    {
        start += strlen( LB );
        if ( end = (char *)strstr( start, RB ) ) //Finds the first occurance of RB in CStr
        {
            CorrParam = ( char * )malloc( end - start + 1 );
            memcpy( CorrParam, start, end - start );
            CorrParam[end - start] = '\0';
        }
    }

    if ( CorrParam )
   
   // printf( "%s\n", CorrParam );
    lr_save_string(CorrParam,"CSMSESSIONID");
    lr_output_message("%s", lr_eval_string("{CSMSESSIONID}"));

    free( CorrParam );
 
    web_save_header(RESPONSE,"");

No comments:

Post a Comment