Highlighted
Contributor.. Contributor..
Contributor..
1798 views

Write a simple c code in loadrunner

Jump to solution

Hello Experts,


Need your help to write a simple c code in loadrunner.

I received string "ZXM6dGM6U0FNTDoyLjA6
cHJvd+jwvc2FtbHA6UmVzcG9uc2U+" from server response which I wish to convert into "ZXM6dGM6U0FNTDoyLjA6&%0D%0AcHJvd%2Bjwvc2FtbHA6UmVzcG9uc2U%2B" format.

I find it very difficult to do hence seeking for help.

BR,

Ak

0 Likes
1 Solution

Accepted Solutions
Highlighted
Frequent Contributor.
Frequent Contributor.

Re: Write a simple c code in loadrunner

Jump to solution

    lr_save_string("ZXM6dGM6U0FNTDoyLjA6
cHJvd+jwvc2FtbHA6UmVzcG9uc2U+", "HTML_text");
    web_convert_param("HTML_text", "SourceEncoding=HTML",  "TargetEncoding=URL", LAST );
    lr_output_message("converted result: %s", lr_eval_string("{HTML_text}"));

Regards,

Bingle(LoadRuner R&D)

 

View solution in original post

3 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Write a simple C code in HPE loadrunner to convert HTML hex escapes

Jump to solution

This is pretty easy:

#include <stdio.h>
#include <string.h>

// converts HTML hex escapes to URL escapes
void convert_html_escapes(const char *in, char *out) {

  for (; in[0] != '\0'; ++in) { // look for "&#x[X]X;", either one or two hex digits if (in[0] == '&' && in[1] == '#' && in[2] == 'x') { *out++ = '%'; in += 3; // skip "&#x" if (in[1] == ';') { // copy one digit *out++ = '0'; *out++ = *in++; } else { // copy two digits *out++ = *in++; *out++ = *in++; } } else { *out++ = *in; } } // for *out = '\0'; } int main(int argc, char **argv) { char buf[512]; const char *in; int i, len; for (i = 1; i < argc; ++i) { in = argv[i]; len = strlen(in); if (len >= sizeof(buf)) { printf("string too long: %d vs %ld: %.20s\n", len, sizeof(buf), in); } else { convert_html_escapes(argv[i], buf); printf("in: %s\n", argv[i]); printf("out: %s\n", buf); } } // for i return 0; }

In your example, sometimes you removed the leading "&" and sometimes you didn't.  I'm assuming you should have always highlighted it and removed it.

Output:

in:  ZXM6dGM6U0FNTDoyLjA6&#xd;&#xa;cHJvd&#x2b;jwvc2FtbHA6UmVzcG9uc2U&#x2b;
out: ZXM6dGM6U0FNTDoyLjA6%0d%0acHJvd%2bjwvc2FtbHA6UmVzcG9uc2U%2b
in:  X&#x99;X
out: X%99X
0 Likes
Highlighted
Frequent Contributor.
Frequent Contributor.

Re: Write a simple c code in loadrunner

Jump to solution

    lr_save_string("ZXM6dGM6U0FNTDoyLjA6&#xd;&#xa;cHJvd&#x2b;jwvc2FtbHA6UmVzcG9uc2U&#x2b;", "HTML_text");
    web_convert_param("HTML_text", "SourceEncoding=HTML",  "TargetEncoding=URL", LAST );
    lr_output_message("converted result: %s", lr_eval_string("{HTML_text}"));

Regards,

Bingle(LoadRuner R&D)

 

View solution in original post

Highlighted
Contributor.. Contributor..
Contributor..

Re: Write a simple c code in loadrunner

Jump to solution

Hi Bingle,

Thanks for your input. It worked as expected.

@Dennis Handly,

Greate code. I thought is impossible but you made it. As of now I will go with Bingles solution as it is readable for me ;).

Definately your piece of code will help me in my furture requirements. Thanks much for your sincere efforts.

BR,

Ak

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.