Greetings,
I’m new to KNIME, and I’m having trouble with REST and Cookies.
I’m trying to replicate the following bit of code in KNIME:
//codestarts
varunirest=require('unirest');
varcookie_jar=unirest.jar();
varhostname='samplehost.corp.airwave.com';
unirest.post('https://'+hostname+'/LOGIN')
.jar(cookie_jar)
.strictSSL(false)
.headers({
'Content-Type':'application/x-www-form-urlencoded'})
.send({
destination:/index.html'
credential_0:'adminusername',//Usernameforadminuser
credential_1:'adminpassword'//Passwordforadminuser
})
.end(function(resp){
vartoken=resp.headers?resp.headers['x-biscotti']:null;
if(token)
{unirest.get('https://'+hostname+'/amp_stats.xml')
//This is an example of calling amp_stats api.
.jar(cookie_jar)
.strictSSL(false)
.headers({
'Content-Type':'application/xml',
'X-BISCOTTI':token
})
.end(function(res)
{console.log(res.body);
});
} else {
Unfortunately, the server in question is behind a firewall, so I can’t give anyone access for testing.
I can log in to the server via KNIME and retrieve the X-BISCOTTI key. However, I can’t get the cookies/cookie jar.
Below is a Python version, and the requests module using the session function takes care of the cookies in the background:
amp_url = 'https://' + AMP
amp_payload = 'credential_0=' + username + '&credential_1=' + password + '&destination=/&login=Log In'
amp_header = {'Content-Type': 'application/x-www-form-urlencoded', 'Cache-Control': 'no-cache'}
try:
with requests.Session() as s:
s.verify = PROJ_PATH + '/.chain.pem'
amp_login = s.post(amp_url + '/LOGIN', headers=amp_header, data=amp_payload, timeout=30)
curl works using the -c flag and a cookie jar file.
I understand I haven’t provided much information here, but I’m stumped.
How can I get the cookie jar in KNIME and use the cookies to authenticate the following GET?
Thanks,
Jeff