cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: [Cookie] Handle a servlet session.

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 17 Oct 2002 08:25:24 +0200 (MET DST)

On Wed, 16 Oct 2002, Fluteau Jerome ICM N PG U PLM A 2 wrote:

> here is my problem: I want to post data on a jsp form, but before accessing
> to the form I have to post an username and a password on a previous jsp
> login page. My problem is that when I post the username and password, I
> receive the same login page as previously, there is no link between the log
> page and the "after login" page.

No? Usually sites pass a cookie back and a Location: header to the page it
wants you to do to after the login.

> The problem is to handle the servlet session I think (jsession_id in the
> header) but I don't exactly know how to do that yet.

Well, unfortunalely, we have different issues to deal with here. libcurl
itself allows pretty flexible ways to solve this, but AFAIK the PHP/CURL
module is not offering access to all those.

If there is a Location returned from the login post, then use FOLLOWLOCATION
and have COOKIEFILE set to a non-existing file (makes it read no cookies by
default but parse returened one). When following the Location, it'll use the
proper cookies in the subsequent request.

You should probably consider using the COOKIEJAR option to have the cookies
stored in a cookie file when the handle is closed, and then set that file
with COOKIEFILE on following requests, which makes them use the proper
cookies automaticly.

> The idea could be to get the jsession_id from the header when connecting to
> the servlet server and then to add it in each request that I send. I try to
> use CURLOPT_COOKIE, CURLOPT_COOKIEJAR,etc. but I have to test them to know
> exactly what they do.

CURLOPT_COOKIEJAR saves cookies in a file.
CURLOPT_COOKIEFILE reads cookies from a file
CURLOPT_COOKIE sets a cookie in a request.

> Do you think it is possible to handle a servlet session?

Oh sure. Been done a million times.

-- 
 Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs.
-------------------------------------------------------
This sf.net email is sponsored by: viaVerio will pay you up to
$1,000 for every account that you consolidate with us.
http://ad.doubleclick.net/clk;4749864;7604308;v?
http://www.viaverio.com/consolidator/osdn.cfm
Received on 2002-10-17