Highlighted
Trusted Contributor.
Trusted Contributor.
435 views

access specific property "Content-Type" from the header object

Jump to solution

I am trying to access specific property "Content-Type" from the header object. I get "Type is not defined, ReferenceError: Type is not defined". It is because of the char "-". With "Date" property is working fine. Please advise how I can access property that has ''-".

 

My request:

const webResponse11 = new load.WebRequest({
id: 11,
url: "http:....../catalog/fetchImage",
method: "GET",
headers: {
"Referer": "http:/......./"
},
queryString: {
"image_id": "1237"
}

My response headers:

{"Cache-Control":"public, max-age=864000","Content-Type":"image/png","Date":"Tue, 21 May 2019 12:24:58 GMT","Expires":"Fri, 31 May 2019 12:24:58 GMT"}

Working example:

load.log("test ===header content type ===" + webResponse11.headers.Date);

Not working example:

load.log("test ===header content type ===" + webResponse11.headers.Content-Type);

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

Hello @vmakaveev,

I apologize for the late reply.

When accessing members of an object with a dash in their name in JavaScript, a common workaround is to access them similar to an array with name based index.

Example: 
header.date is the same as header["date"] 

or headers["Content-Type"] in your case.

Hope that helps,

Gil

 

View solution in original post

8 Replies
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Hi vmkaavev,

maybe I don't undestrand correctly your problem, but if you want to add a specification of the Content-Type on the header frame of your request to send, you have to set the option "RecContentType" on the web_custom_request() function, 

   web_custom_request("...

         "RecContent-Type=image/png", 

        ...

or your can add it with web_add_header() function. 

Let me know if this simple suggestion has helped you with the issue,

Lorenzo

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

HI Lorenzo,

I would like to access my response header "Content-type" from the response.

Thanks,

 

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

also I am using TruWeb protocol....

0 Likes
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Have you try with a web_reg_save_param()? This function allow you to catch a particular value from the response and handle it with bytecode. You have to point left and right limits of the value you want to obtain. For example, 

   web_reg_save_param_ex(

         "ParamName=<paramName>",

        "LB=<leftLimit>", "RB=<rightLimit>",

        SEARCH_FILTERS,

       "Scope=Body", "RequestUrl=<yourUrl>", LAST);

Let me know!

Lorenzo

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

Hi Lorenzo,

Thank you for your reply. Acctually I am using TruWeb protocol and this function will not help me. Anyway I have workaround and to use "match" or "includes" when I convert the obejct "headers" to string. I would like someone to advise how to access directly this property from headers object. For property "Date" is working, but for a property, that contains '-' is not working. 

BR,

Valentin

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

Hi Lorenzo,

Thank you for your reply. Acctually I am using TruWeb protocol and this function will not help me. Anyway I have workaround and to use "match" or "includes" when I convert the obejct "headers" to string. I would like someone to advise how to access directly this property from headers object. For property "Date" is working, but for a property, that contains "-" is not working. 

BR,

Valentin

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Hello @vmakaveev,

I apologize for the late reply.

When accessing members of an object with a dash in their name in JavaScript, a common workaround is to access them similar to an array with name based index.

Example: 
header.date is the same as header["date"] 

or headers["Content-Type"] in your case.

Hope that helps,

Gil

 

View solution in original post

Highlighted
Trusted Contributor.
Trusted Contributor.

Hi,

Thank you!

Best Regards,

 

Valentin

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.