SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 6 of 6
  1. #1
    Junior Member
    Join Date
    Nov 2001
    Location
    Pune, India
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    How to encode parameters

    Hi,

    Can anyone tell me how to encode parameters
    in Loadrunner?
    I need to correlate a particular value in a name value pair say:
    name=hi value=Hello & World

    What happens is when i go to create a correlation parameter in the html data of LoadRunner the above value is being displayed in html as "Hello & World"
    ie the & is being displayed in html as &

    Therefore when i try to reuse the
    created correlation parameter WCSParam_Text1
    in a subsequent POST request it fails,
    as "Hello & World" is getting submitted
    instead of just "Hello & World".

    Do i need to encode this parameter again before using it again.
    If yes,how to do that.
    Is there any other solution for this problem?

    Pls let me know,

    Thanks,
    U Mehta


    ------------------
    Utpal Mehta
    Utpal Mehta

  2. #2
    Junior Member
    Join Date
    Nov 2001
    Location
    Pune, India
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to encode parameters

    Hey even here its the same prob.
    Actually i meant "&" is getting replaced by
    "&"


    ------------------
    Utpal Mehta
    Utpal Mehta

  3. #3
    Junior Member
    Join Date
    Nov 2001
    Location
    Pune, India
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to encode parameters

    "&" by "& amp;"

    ------------------
    Utpal Mehta
    Utpal Mehta

  4. #4
    Member
    Join Date
    Aug 2002
    Location
    Seattle, Wa USA
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to encode parameters

    It's hard to say exactly what your problem is because everything you posted was unencoded.

    However, if I understand, you grab some data, say "Hello & World", then the next time it is needed, that ampersand is supposed to be encoded for the page to understand it right? But since you don't have it parameterized as URL encoded text, then it's throwing an ASP 500 error or something.

    The answer is to do something like this:
    char EncodedString[3 * length of parameter value] = "";
    URLEncodeText(lr_eval_string("{your_parameter}"), EncodedString);
    lr_save_string(EncodedString, "your_parameter_encoded");
    web_submit_data(...
    "Name=field, Value={your_parameter_encoded}", ENDITEM);

    Of course, you'll need to write the function URLEncodeText() to encode your text. If you have trouble doing this, I have one I can post here for you to use, as I ran into this problem a while back.

    ------------------
    EDIT: After re-reading, my explanation sounds a little confusing even to myself. I'll post some sample code tomorrow when I'm in the office to show you what I'm talking about.

    [This message has been edited by shep_bannister (edited 10-07-2002).]

  5. #5
    Member
    Join Date
    Aug 2002
    Location
    Seattle, Wa USA
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to encode parameters

    Sorry it took me so long to reply, I woke up with a deadly sore throat the next morning and ended up staying away from the office.

    Here is the URL_Encode function that I use most often. It's written so that it incorporates LR's library functions in it, which means you can't make a dll out of this, but it's really easy to use as a result.

    Here's the code:
    /*
    * This function encodes string and saves it to parameter whose name
    * is the value of output_param_name
    * Pre: string contains the string to URL_Encode
    * Post: A Parameter is created with the name of output_param_name's value
    */
    URL_Encode_ToParameter(const char * string, const char * output_param_name)
    {
    int in,out; //counters
    char buffer[4]; //temporary buffer
    char * encoded_output = (char *)malloc((strlen(string)*3)+1); //need enough room for all chars to encode

    lr_save_string("",output_param_name);

    //run through the entire string
    for (in=0,out=0; in<(int)strlen(string); in++,out++)
    {
    //If string[in] is a number or letter, don't encode it
    if (isalnum(string[in]))
    encoded_output[out] = string[in];

    //otherwise, encode it and copy it to encoded_output[out]
    else
    {
    sprintf(buffer, "%%%X", string[in]);
    memcpy(&encoded_output[out], buffer, 3);
    out+=2;
    }

    } //for...

    //terminate the output string
    encoded_output[out] = '\0';

    lr_save_string(encoded_output, output_param_name);

    free(encoded_output);

    return;
    }

    ------------------

  6. #6
    Member
    Join Date
    Aug 2002
    Location
    Seattle, Wa USA
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to encode parameters

    Here is the unencode function (to go from encoded to not encoded):

    /*
    * Unencode string then save the result to the parameter whose name is
    * specified by the value of output_param_name
    * Pre: string contains the string to URL_Unencode
    * Post: output_param_name contains the name of the param with the
    * unencoded result
    */
    URL_Unencode_ToParameter(const char *string, const char * output_param_name)
    {
    int in, out; //counters
    long conversion; //temporary placeholder
    char buffer[3]; //temporary buffer
    char *unencoded_output = (char *)malloc(strlen(string)+1);

    lr_save_string("",output_param_name);

    //Run through the entire string
    for (in=0,out=0; in<(int)strlen(string); in++,out++)
    {
    //If we find an encoded section, unencode it
    if (string[in] == '%')
    {
    ++in;
    memcpy(buffer, &string[in], 2);
    buffer[2] = '\0';
    conversion = strtol(buffer, NULL, 16);
    sprintf(buffer, "%c", conversion);
    memcpy(&unencoded_output[out], buffer, 1);
    ++in;
    }

    //Otherwise just copy the char over
    else
    unencoded_output[out] = string[in];
    } //for ...

    //terminate the output string
    unencoded_output[out] = '\0';

    lr_save_string(unencoded_output, output_param_name);

    free(unencoded_output);

    return;
    }


    You call either of these like this:
    //parameter {string} encodes to new parameter {encoded_string}
    URL_Encode_ToParameter(lr_eval_string("{string}"), "encoded_string");

    //parameter {encoded_string} unencodes to new parameter {string}
    URL_Unencode_ToParameter(lr_eval_string("{encoded_ string}"), "string");

    ------------------

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 03:06 PM.

Copyright BetaSoft Inc.