Hi,

Restlet rocks. Thanks to Jerome and all the contributors for a job well done.

I have been having trouble figuring out how to add a cookie to a client request. I am using Restlet to build client-side tests for a RESTful service. The server sends a cookie, which I can get using:

String cookie = response.getCookieSettings().getValues("MyCookieName");

However, it is unclear to me how to send that cookie back to the server in subsequent requests. I tried adding it to the client's context, like this:

try {
        // TODO: Try to add the cookie as a Cookie object.
        Cookie myCookie = new Cookie("MyCookieName", cookie);
        client.getContext().getParameters().add(myCookie);
        client.start();
} catch (Exception e) {
System.err.println("Unexpected exception trying to restart the Restlet client. Exiting!\n" + e);
        System.exit(1);
}

and, indeed, the cookie is added to the client's parameters. It is just not sent to the server upon future HTTP connections. Can anyone tell me whether Restlet supports sending of cookies from a Restlet client and how to do it? Thanks in advance!

Regards,
Dave



Reply via email to