- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 06:48 AM
Hi,
I have created a scripted REST API where I am fetching the HTTP headers by using the below function
request.getHeader('header name').
But I want to fetch all the headers that we receive in the request. I tried to use request.headers as suggested in docs but it gives me [object Object]
Any suggestions?
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 08:52 AM
Please try this, You should convert the Json to string
var header = request.headers;
var json = new JSON();
var headerStr = json.encode(header);
gs.log(headerStr);
Thanks
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 08:14 AM
Hi Aswin,
You can get all the header values using response object.Try below code
var response = res.execute(); // res is restmessage object
var error = response.haveError();
var responseBody = response.getBody();
then parse the values using "JSON.parse(responseBody);"
Regards
Anantha Gowraram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 08:39 AM
Are you saying I will get the http headers by parsing response body?
On Wed, 1 Mar 2017 at 9:44 PM, ananthagowraram <
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 08:37 AM
Hi Aswin,
request.headers returns a json string of header values
You can try these lines to get individual header values
var headers = request.headers;
var acceptHeader = headers.Accept;
OR Loop
var header = request.headers;
for (var i in header){
gs.log(i + " - " + header[i],"Result");
}
where i = header label and header[i] is its value
Thanks
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 08:42 AM
Headers.accept will give me the value for http header content-type and not
all headers.
For loop is going to run for number of headers available? Is there no way
to get all the headers without a loop?
On Wed, 1 Mar 2017 at 10:07 PM, alikuttyka <