Highlighted
Valued Contributor.
Valued Contributor.
1833 views

In Web_custom request, there is extra escape character placed automatically.

Jump to solution

Hi All,

I have a scenario where I need to pass request as "\"xxxx-xxxx-xxx\"" in web_custom_request body. When I replay the script, in the body Vugen is appending extra \ as shown here "\\"xxxx-xxxx-xxx\\"", which my server is not accepting and request getting failed.

Load runner Version - 12.5

Please let me know any solution or best alternative for this problem.

Thanks for help in advance.

-Vineet

0 Likes
1 Solution

Accepted Solutions
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

If you see the extra backslash in the logging of LR, you are right. But that extra backslash is not send over the wire.

I did a quick test and removed a single backslash from my string (that is a double backslash in my C-code). I noticed that LR sent one byte less over the wire. Check your logging for e.g.

Action.c(146): t=495ms: 56-byte request body for "http://httpbin.org/get" (RelFrameId=1, Internal ID=1)

Signature:
Reward community members who take time to respond and help.

View solution in original post

0 Likes
8 Replies
Highlighted
Honored Contributor.
Honored Contributor.

if you want to send "xxxx-xxxx-xxx" in the body:


web_custom_request("web_custom_request",
"URL=http://some.server.com",
"Method=GET",
"TargetFrame=",
"Resource=0",
"Referer=",
"Body=\"xxxx-xxxx-xxx\"",
LAST);

 

if you want to send \"xxxx-xxxx-xxx\"

"Body=\\\"xxxx-xxxx-xxx\\\"",

Micro Focus Performance Core.
Functional Architect
your performance, our passion!
0 Likes
Highlighted
Valued Contributor.
Valued Contributor.

Hi Moshka,

Tried adding "Body=\\\"xxxx-xxxx-xxx\\\"",  but when it send request to server, i see as "Body=\\"xxxx-xxxx-xxx\\"" which my server is not able to accept the request which is expecting only 1 back slash.

Thanks,

Vineet

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

If you see the extra backslash in the logging of LR, you are right. But that extra backslash is not send over the wire.

I did a quick test and removed a single backslash from my string (that is a double backslash in my C-code). I noticed that LR sent one byte less over the wire. Check your logging for e.g.

Action.c(146): t=495ms: 56-byte request body for "http://httpbin.org/get" (RelFrameId=1, Internal ID=1)

Signature:
Reward community members who take time to respond and help.

View solution in original post

0 Likes
Highlighted
Valued Contributor.
Valued Contributor.

Thank you very much!

-Vineet

0 Likes
Highlighted
Contributor.
Contributor.

I have the same issue.

I need to send this type of request (note backslashes inc - in red here):

{"ParametersAsString":"{\"ConnectionToken\":{\"Token\":\"Qkg7e/glSxsyvj/SphYFcmCNegiPvhGCsMEi8LHvazDBk1zYqEqUUujqwQ02J6BLxWL3XRR6oADmQFA4DPlR3w==\"}}","Id":"e8b63054738aa3c0db6ed8b8755c11e8a95c369b"}

However, when include the \\ to escape the backslash and send just one (as per below) it sends two \\  :

{"ParametersAsString":"{\\\"ConnectionToken\\\":{\\\"Token\\\":\\\"Qkg7e/glSxsyvj/SphYFcmCNegiPvhGCsMEi8LHvazDBk1zYqEqUUujqwQ02J6BLxWL3XRR6oADmQFA4DPlR3w==\\\"}}","Id":"e8b63054738aa3c0db6ed8b8755c11e8a95c369b"}

{"ParametersAsString":"{\\"ConnectionToken\\":{\\"Token\\":\\"Qkg7e/glSxsyvj/SphYFcmCNegiPvhGCsMEi8LHvazDBk1zYqEqUUujqwQ02J6BLxWL3XRR6oADmQFA4DPlR3w==\\"}}","Id":"e8b63054738aa3c0db6ed8b8755c11e8a95c369b"}

Then the server returns "The message sent to the server was corrupted so has been ignored"

If I don't include the backslashes so only the " are sent it fails. 

So.. just \" fails.   \\\" also fails.  \\" obviously doesn't even parse.

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

When you need to send over the string

{"ParametersAsString":"{\"ConnectionToken\":{\"Token\":\"Qkg7e/glSxsyvj/SphYFcmCNegiPvhGCsMEi8LHvazDBk1zYqEqUUujqwQ02J6BLxWL3XRR6oADmQFA4DPlR3w==\"}}","Id":"e8b63054738aa3c0db6ed8b8755c11e8a95c369b"}

You have to put it into a C-string argument. This implies you have to surround the message with double quotes. To be able to include double quotes into your C-string argument you have to escape those with \, so you have to escape any \ as well with \ to be deterministic. So your C-string argument needs to look like:

"{\"ParametersAsString\":\"{\\\"ConnectionToken\\\":{\\\"Token\\\":\\\"Qkg7e/glSxsyvj/SphYFcmCNegiPvhGCsMEi8LHvazDBk1zYqEqUUujqwQ02J6BLxWL3XRR6oADmQFA4DPlR3w==\\\"}}\",\"Id\":\"e8b63054738aa3c0db6ed8b8755c11e8a95c369b\"}"

Note: there are even online websites available for this trivial task. java dotnet escape (This works also for C-code)

Signature:
Reward community members who take time to respond and help.
0 Likes
Highlighted
Contributor.
Contributor.

So to be clear..

LR records the request with \\\" meaning the backslash should be in the request and manually the request looks like \", so it appears LR is doing the right thing, it's including the backslash and escaping it.

On playback it looks like (according to logs) it's sending \\" and so response is 'Message Corrupted'. 

Why doesn't LR actually send a single backslash - why is it sending two?

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

The recorded log of what is sent is not represented correctly. LR messages with backslashes, but WHAT is sent is correct is my experience. When you want to check this, you might play with an public json test service that response back what you sent or you can use wireshark to check what is going in all its nice details over the wire.

Signature:
Reward community members who take time to respond and help.
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.