07 Dec 2023 10:01 AM - last edited on 11 Dec 2023 08:25 AM by MaciejNeumann
Hello,
I'm building an HTTP monitor and in one HTTP request, I try to get the value of one header.
The problem is I receive the value with brackets.
I tried to remove them with replace() or substring() but it is failing: UNKNOWN_METHOD_ERROR
How can I remove them?
Many thanks in advance for your answer,
Warm Regards,
Sabine
Example:
"responseHeaders": [
{
"name": "blabla",
"value": "myvalue"
},
Post script:
var resp = response.getHeaders().getAll('blabla');
api.setValue("myValue", resp);
Result of myValue : "[myvalue]"
Solved! Go to Solution.
07 Dec 2023 11:48 AM
Hi,
Maybe this:
var resp = response.getHeaders().getAll('blabla');
resp = resp.replace('[','')
resp = resp.replace(']','')
api.setValue("myValue", resp);
But you can explore other ways to remove a character from a string.
Best regards
07 Dec 2023 11:54 AM
I tried it and it failed with error returned: Unknown method or invalid set of parameters.
Same with:
var resp1 = resp.substring(1, resp.length - 1);
07 Dec 2023 01:11 PM - edited 07 Dec 2023 06:25 PM
Hi,
Maybe it because "resp" is not a string and it is an object.
My next actions would be:
Best regards
07 Dec 2023 01:59 PM
Yes, that was it:
I converted it in string, removed the 2 brackets, and now it works.
Thank you for your help!
Sabine
---------------------------------------------------------------
var resp = String(response.getHeaders().getAll('blabla'));
var resp1 = resp.substring(1, resp.length - 1);
api.setValue("myvalue", resp1);