Webclient Cookies

I have been banging my head against the wall trying to get the http plugin to work for one of our solutions.

I would like to be able to save text entered into a field as a cookie and then later, after closing and reopening the browser, be able to get that data from the cookie to have the field filled in already.

We need this to do a “remember me” checkbox on a login name field on our webclient solution.

Here is some test code I’ve been using.

runs on solution load to start the http client

function onload () {
	plugins.http.createHttpClient('DexOnline')
}

onaction event for a button to create the cookie after text entered into test field

function savecookie () {
	plugins.http.setHttpClientCookie( 'DexOnline',  'DexOnlineUID',  UID, 'ourwebsite.com', '/', 10000000, false)
}

onaction event for a button to put cookie data in the show variable.

function testcookie () {
	var cookie = plugins.http.getHttpClientCookie( 'DexOnline', 'DexOnlineUID')
	show = cookie.getValue() + ' - ' + cookie.getComment() + ' - ' + cookie.getDomain() + ' - ' + cookie.getName() + ' - ' + cookie.getPath() + ' - ' + cookie.getSecure()
}

This all works great in a single session. Problem is that the cookie expires when the browser is closed. How can we make the cookie expire much later?

Thanks!

the http plugin is another browser by itself, so that is not the browser of the user… You are creating another kind of browser on the server here (where the webclient code runs)

setting a cookie on the users browser is done by: application.setUserProperty(“key”,“value”);

I just ran a test using application.setuserproperty and it looks like that is going to work exactly as we’d like it to.

Thanks for the info! I never would have guess using that to set a browser cookie.

Keep in mind that the API in Servoy in client agnostic: a function to set a cookie wouldn’t make a lot of sense if you’d be running a Smart Client, because it’s a browser thing.

Paul