How can i get and set cookie parameter in REST Message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2015 03:15 AM
How can i get and set cookie parameter in REST Message? i have tried to use getCookies(), setCookies(), getHeader() but not able to get response properly... on trying getHeader("set-cookie") it gives the complete header value and i am not able to set it.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2015 01:27 AM
yes i am able to get cookie value but i need to set some unique value in cookie param of Header when i call the next REST Message in order to link two web service call... addHeader("set-cookie", "xyz Value"); this is the syntax i cud find in wiki but it doesn't help and i am still receiving a concurrency issue.
I guess am not able to explain the scenario very clearly...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2015 03:35 AM
Not sure it's exactly the same scenario but this is what I've got working (just). The downside is I've only managed to get this working in our Fuji instance. I can't seem to access the response header data prior to Fuji...
We have an app which requires a auth request to get a token and cookie. The token and cookie is then passed to all subsequent requests to authenticate.
I get the key and cookie using this:
sApiKey = json.apiKey;
aHeaders = response.getHeaders();
for ( row in aHeaders ) { if ( row == 'Set-Cookie' ) { sCookie = getCookie(aHeaders[row]); } }
function getCookie(inString) {
inString = inString.split(';');
return inString[0];
}
I can then set the auth token and cookie using this:
rest.setRequestHeader('Cookie', inCookie);
rest.setRequestHeader('Authorization', inToken);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2015 04:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2017 09:18 AM
Iain,
I'm trying to do the same thing but I'm unable to recreate what you did. Do you still have this example on how to use cookies for REST authentication?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2017 12:19 PM
Hello, we didn't continue with this route since the target started supporting oauth. I've tried to re-create an example from memory. Hopefully it helps. It gets NID then attempts to set it in the next request (I know it's a bit duff, but I couldn't think of a site to do this with right now):
var sNid = '';
sNid = getHttpNid(sNid);
gs.print(sNid);
sNid = getHttpNid(sNid);
gs.print(sNid);
function getHttpNid(inNid) {
var oResponse, oHeaders, oCookies;
var nStatusCode = 500, sResponseBody, sRequestBody;
var sNid;
var rest = new sn_ws.RESTMessageV2();
rest.setHttpMethod('GET');
rest.setEndpoint('http://www.google.co.uk');
if ( JSUtil.notNil(inNid) ) { rest.setRequestHeader('NID', inNid); }
rest.setRequestHeader('cache-control', 'no-cache');
try {
oResponse = rest.execute();
nStatusCode = oResponse.getStatusCode();
sResponseBody = oResponse.getBody();
oHeaders = oResponse.getHeaders();
sCookies = oResponse.getRequestHeader('Set-Cookie');
} catch ( err ) {
sResponseBody = err.getMessage();
} finally {
sRequestBody = oResponse.getRequestBody();
}
if ( JSUtil.nil(oCookies) ) { for ( row in oHeaders ) { if ( row == 'Set-Cookie' ) { oCookies = oHeaders[row].toString(); } } }
oCookies = oCookies.split('; ');
for ( var i = 0; i < oCookies.length; i++ ) { if ( oCookies[i].indexOf('NID=') >= 0 ) { sNid = oCookies[i].replace(/NID=/, ''); break; } }
return sNid;
}