cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Http Monitor - get header without brackets

SabineR
Participant

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]"

 

4 REPLIES 4

AntonPineiro
DynaMight Leader
DynaMight Leader

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

❤️ Emacs ❤️ Vim ❤️ Bash ❤️ Perl

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);

 

Hi,

Maybe it because "resp" is not a string and it is an object.

My next actions would be:

  • Checking type of "resp". Maybe using "typeof".
  • Transform/extract string value.

Best regards

❤️ Emacs ❤️ Vim ❤️ Bash ❤️ Perl

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);

 

 

Featured Posts