Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Hi,
I need to pass a cookie as header to server in order to get data from that.
For this I am Using following:
var Cookieparams = {
proxyScheme: undefined /* STRING */,
headers: {"Cookie":"UFJKKFF838NNBDH38B"} /* JSON */,
ignoreSSLErrors: true /* BOOLEAN */,
withCookies: true /* BOOLEAN */,
url: "url?Parameters" /* STRING */,
};
// result: STRING
var result = Resources["ContentLoaderFunctions"].GetJSON(Cookieparams);
As a result it's displaying "No active sessions with given cookie". I suspect problem caused because of above code.
Please suggest a way to pass cookie as header.
Thanks,
Meenakshi
Solved! Go to Solution.
This is the correct method; the important difference is that you are using the result of GetCookies as the cookie header. Note that sometimes the cookie result goes into a Cookie header, as in the original post:
i.e:
var params = {
proxyScheme: undefined /* STRING */,
// headers: {"JSESSIONID":"4C211033F290F29A152173A47A26FC78"} /* JSON */,
ignoreSSLErrors: true /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
withCookies: true /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: "http://localhost:8080/Thingworx/Things" /* STRING */,
timeout: undefined /* NUMBER */,
proxyPort: undefined /* INTEGER */,
password: "admin" /* STRING */,
domain: "http://localhost:8080/" /* STRING */,
username: "Administrator" /* STRING */
};
// result: STRING
var cookieResult = Resources["ContentLoaderFunctions"].GetCookies(params);
var Cookieparams = {
proxyScheme: undefined /* STRING */,
headers: {"Cookie":cookieResult } /* JSON */,
ignoreSSLErrors: true /* BOOLEAN */,
withCookies: true /* BOOLEAN */,
url: "url?Parameters" /* STRING */,
};
// result: STRING
var result = Resources["ContentLoaderFunctions"].GetJSON(Cookieparams);
This will depend on the format required by the receiving server, but should match whatever works in postman.
var params = {
proxyScheme: undefined /* STRING */,
// headers: {"JSESSIONID":"4C211033F290F29A152173A47A26FC78"} /* JSON */,
ignoreSSLErrors: true /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
withCookies: true /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: "http://localhost:8080/Thingworx/Things " /* STRING */,
timeout: undefined /* NUMBER */,
proxyPort: undefined /* INTEGER */,
password: "admin" /* STRING */,
domain: "http://localhost:8080/" /* STRING */,
username: "Administrator" /* STRING */
};
// result: STRING
var result = Resources["ContentLoaderFunctions"].GetCookies(params);
// result: JSON
//var result = Resources["ContentLoaderFunctions"].GetJSON(params); // Return JSON
You can get cookie first or pass in the cookie using get cookie then use GetJSON and pass cookie from the result set of GetCookies to get the data what you need
I can get cookie as well as set cookie see above or let me know you need any other way to achieve it
Thanks Niesh,
I am doing the exactly as I mentioned. I am able to get cookies from the server but when requesting GETJson with received cookie I am always getting "No active session". Same thing I can perform through POSTMAN.
I could not encountered the error you are facing tried with postman as well ,
my whole code
var params = {
proxyScheme: undefined /* STRING */,
// headers: {"JSESSIONID":"4C211033F290F29A152173A47A26FC78"} /* JSON */,
ignoreSSLErrors: true /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
withCookies: true /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: "http://localhost:8080/Thingworx/Things" /* STRING */,
timeout: undefined /* NUMBER */,
proxyPort: undefined /* INTEGER */,
password: "admin" /* STRING */,
domain: "http://localhost:8080/" /* STRING */,
username: "Administrator" /* STRING */
};
// result: STRING
var cookieResult = Resources["ContentLoaderFunctions"].GetCookies(params);
var params = {
proxyScheme: undefined /* STRING */,
headers: {"JSESSIONID":cookieResult} /* JSON */,
ignoreSSLErrors: true /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
withCookies: true /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: "http://localhost:8080/Thingworx/Things" /* STRING */,
timeout: undefined /* NUMBER */,
proxyPort: undefined /* INTEGER */,
password: "admin" /* STRING */,
domain: "http://localhost:8080/" /* STRING */,
username: "Administrator" /* STRING */
};
// result: JSON
var result = Resources["ContentLoaderFunctions"].GetJSON(params); // REturn JSON
Output is JOSN
You may try with different username and pass
This is the correct method; the important difference is that you are using the result of GetCookies as the cookie header. Note that sometimes the cookie result goes into a Cookie header, as in the original post:
i.e:
var params = {
proxyScheme: undefined /* STRING */,
// headers: {"JSESSIONID":"4C211033F290F29A152173A47A26FC78"} /* JSON */,
ignoreSSLErrors: true /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
withCookies: true /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: "http://localhost:8080/Thingworx/Things" /* STRING */,
timeout: undefined /* NUMBER */,
proxyPort: undefined /* INTEGER */,
password: "admin" /* STRING */,
domain: "http://localhost:8080/" /* STRING */,
username: "Administrator" /* STRING */
};
// result: STRING
var cookieResult = Resources["ContentLoaderFunctions"].GetCookies(params);
var Cookieparams = {
proxyScheme: undefined /* STRING */,
headers: {"Cookie":cookieResult } /* JSON */,
ignoreSSLErrors: true /* BOOLEAN */,
withCookies: true /* BOOLEAN */,
url: "url?Parameters" /* STRING */,
};
// result: STRING
var result = Resources["ContentLoaderFunctions"].GetJSON(Cookieparams);
This will depend on the format required by the receiving server, but should match whatever works in postman.
Thanks James McCuen,
I did the same as your instructions but still getting "No active session with supplied cookie" on passing received cookie as a header. I am getting cookie from our server. Is there any possibility that Thingworx cookie JSESSIONID is overwriting my server's cookie which I am sending in header and that's why it is always responding that there is no active session with supplied cookie.
Meenakshi
Hey James McCuen,
It's working for me as well now. The problem was due to spaces in headers.
My code was:
headers:{"Cookie":cookieResult} /* JSON */,
and the code that works as expected for me is:
headers: { "Cookie" : cookieResult } /* JSON */,
Thanks,
Meenakshi