[Haskell-beginners] network.curl wondering about the relationship between CurlCookieJar and CurlCookieFile

Michael Litchard michael at schmong.org
Sat Oct 23 17:35:46 EDT 2010


The problem is, while doing an HTTP(S) conversation between my client,
and the application server, there's a point where the server delivers
a a few new cookies. Now, I am able to get the initial cookies for the
jar, but I don't get the new cookies when I am supposed to. I started
looking at the various constructors offered by Network.Curl and came
across CurlCookieFile. I'm wondering if this is the missing piece. If
I need it, how does it fit in with CurlCookieJar?
I'm including my current code, and the headers I'm getting. I'll note
where the cookies are supposed to come in but don't.

Any clues on how to troubleshoot, and some info on CurlCookieFile
would be greatly appreciated.

> import Network.Curl
> import System (getArgs)
> import Text.Regex.Posix

> -- | Standard options used for all requests. Uncomment the @CurlVerbose@
> -- option for lots of info on STDOUT.
> opts = [CurlCookieJar "cookies" , CurlVerbose True, CurlFollowLocation True]

> -- | Additional options to simulate submitting the login form.
> loginOptions user pass =
>   method_POST ++ [CurlPostFields [ "login=" ++ user, "password=" ++ pass ]]

> main = withCurlDo $ do
>   -- Get username and password from command line arguments (will cause
>   -- pattern match failure if incorrect number of args provided).
>   [user, pass] <- getArgs

>   -- Initialize curl instance.
>   curl <- initialize
>   setopts curl opts

>   -- GET initial request
>   r <- do_curl_ curl ("https://172.16.1.18/showLogon.do") method_GET
>     :: IO CurlResponse

>   -- POST request to login.
>   r <- do_curl_ curl "https://172.16.1.18/default/showLogon.do" (loginOptions user pass)
>     :: IO CurlResponse
>   if respCurlCode r /= CurlOK || respStatus r /= 200
>     then error $ "Failed to log in: "
>                ++ show (respCurlCode r) ++ " -- " ++ respStatusLine r
>     else do
>       -- POST request showFlashCheck.do
>       r <- do_curl_ curl ("https://172.16.1.18/showFlashCheck.do") method_GET
>         :: IO CurlResponse
>       if respCurlCode r /= CurlOK || respStatus r /= 200
>         then error $ "Failed at showFlashCheck.do: "
>                    ++ show (respCurlCode r) ++ " -- " ++ respStatusLine r
>         else do
>            -- GET request

>           r <- do_curl_ curl ("https://172.16.1.18/logon.do?flashVersion=9.0.100") method_GET --- right here, the server should respond with more cookies

>             :: IO CurlResponse
>           if respCurlCode r /= CurlOK || respStatus r /= 200
>             then error $ "Failed at login.do?flashVersion=10.0"
>                        ++ show (respCurlCode r) ++ " -- " ++ respStatusLine r
>             else do
>               -- go go gadget webForwards!
>                r <- do_curl_ curl ("https://172.16.1.18/launchWebForward.do?resourceId=4&policy=0&returnTo=%2FshowWebForwards.do") method_GET
>                  :: IO CurlResponse
>                if respCurlCode r /= CurlOK || respStatus r /= 200
>                  then error $ "Failed at Web Foward"
>                              ++ show (respCurlCode r) ++ " -- " ++ respStatusLine r
>                  else putStrLn $ respBody r


Headers ....> GET /showLogon.do HTTP/1.1
Host: 172.16.1.18
Accept: */*

< HTTP/1.1 200 OK
< Date: Sat, 23 Oct 2010 21:32:09 GMT
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
* Added cookie SSLX_SSESHID="5oskk7cts6epk" for domain 172.16.1.18,
path /, expire 0
< Set-Cookie: SSLX_SSESHID=5oskk7cts6epk;Path=/
* Added cookie lbTrack="BFQZHBGQBMURVJWIMWXTPIGSYYPCRCRTLSJUZBMJYZCQTTXNSVPH--------"
for domain 172.16.1.18, path /, exp
ire 1287870429
< Set-Cookie: lbTrack=BFQZHBGQBMURVJWIMWXTPIGSYYPCRCRTLSJUZBMJYZCQTTXNSVPH--------;Path=/;Expires=Sat,
23-Oct-10 21:47:09
 GMT;Secure
< Content-Type: text/html;charset=UTF-8
< Pragma: no-cache
< Cache-Control: no-cache
< Transfer-Encoding: chunked
<
* Connection #0 to host 172.16.1.18 left intact
* Re-using existing connection! (#0) with host 172.16.1.18
* Connected to 172.16.1.18 (172.16.1.18) port 443 (#0)
> POST /default/showLogon.do HTTP/1.1
Host: 172.16.1.18
Accept: */*
Cookie: lbTrack=BFQZHBGQBMURVJWIMWXTPIGSYYPCRCRTLSJUZBMJYZCQTTXNSVPH--------;
SSLX_SSESHID=5oskk7cts6epk
Content-Length: 32
Content-Type: application/x-www-form-urlencoded

< HTTP/1.1 200 OK
< Date: Sat, 23 Oct 2010 21:32:09 GMT
< Content-Type: text/html;charset=UTF-8
< Pragma: no-cache
< Cache-Control: no-cache
< Transfer-Encoding: chunked
<
* Connection #0 to host 172.16.1.18 left intact
* Re-using existing connection! (#0) with host 172.16.1.18
* Connected to 172.16.1.18 (172.16.1.18) port 443 (#0)
> GET /showFlashCheck.do HTTP/1.1
Host: 172.16.1.18
Accept: */*
Cookie: lbTrack=BFQZHBGQBMURVJWIMWXTPIGSYYPCRCRTLSJUZBMJYZCQTTXNSVPH--------;
SSLX_SSESHID=5oskk7cts6epk

< HTTP/1.1 200 OK
< Date: Sat, 23 Oct 2010 21:32:09 GMT
< Content-Type: text/html;charset=UTF-8
< Transfer-Encoding: chunked
<
* Connection #0 to host 172.16.1.18 left intact
* Re-using existing connection! (#0) with host 172.16.1.18
* Connected to 172.16.1.18 (172.16.1.18) port 443 (#0)
> GET /logon.do?flashVersion=9.0.100 HTTP/1.1                <------ right here is where it falls down. No cookies for me.

Host: 172.16.1.18
Accept: */*
Cookie: lbTrack=BFQZHBGQBMURVJWIMWXTPIGSYYPCRCRTLSJUZBMJYZCQTTXNSVPH--------;
SSLX_SSESHID=5oskk7cts6epk

< HTTP/1.1 302 Moved Temporarily
< Date: Sat, 23 Oct 2010 21:32:09 GMT
< Content-Type: text/html
< Location: https://172.16.1.18/default/showLogon.do?msgId=0
< Content-Length: 0
<
* Connection #0 to host 172.16.1.18 left intact
* Issue another request to this URL:
'https://172.16.1.18/default/showLogon.do?msgId=0'
* Re-using existing connection! (#0) with host 172.16.1.18
* Connected to 172.16.1.18 (172.16.1.18) port 443 (#0)
> GET /default/showLogon.do?msgId=0 HTTP/1.1
Host: 172.16.1.18
Accept: */*
Cookie: lbTrack=BFQZHBGQBMURVJWIMWXTPIGSYYPCRCRTLSJUZBMJYZCQTTXNSVPH--------;
SSLX_SSESHID=5oskk7cts6epk

< HTTP/1.1 200 OK
< Date: Sat, 23 Oct 2010 21:32:09 GMT
< Content-Type: text/html;charset=UTF-8
< Pragma: no-cache
< Cache-Control: no-cache
< Transfer-Encoding: chunked
<
* Connection #0 to host 172.16.1.18 left intact
* Re-using existing connection! (#0) with host 172.16.1.18
* Connected to 172.16.1.18 (172.16.1.18) port 443 (#0)
> GET /launchWebForward.do?resourceId=4&policy=0&returnTo=%2FshowWebForwards.do HTTP/1.1
Host: 172.16.1.18
Accept: */*
Cookie: lbTrack=BFQZHBGQBMURVJWIMWXTPIGSYYPCRCRTLSJUZBMJYZCQTTXNSVPH--------;
SSLX_SSESHID=5oskk7cts6epk

< HTTP/1.1 302 Moved Temporarily
< Date: Sat, 23 Oct 2010 21:32:09 GMT
< Content-Type: text/html
< Location: https://172.16.1.18/default/showLogon.do
< Content-Length: 0
<
* Connection #0 to host 172.16.1.18 left intact
* Issue another request to this URL: 'https://172.16.1.18/default/showLogon.do'
* Re-using existing connection! (#0) with host 172.16.1.18
* Connected to 172.16.1.18 (172.16.1.18) port 443 (#0)
> GET /default/showLogon.do HTTP/1.1
Host: 172.16.1.18
Accept: */*
Cookie: lbTrack=BFQZHBGQBMURVJWIMWXTPIGSYYPCRCRTLSJUZBMJYZCQTTXNSVPH--------;
SSLX_SSESHID=5oskk7cts6epk

< HTTP/1.1 200 OK
< Date: Sat, 23 Oct 2010 21:32:09 GMT
< Content-Type: text/html;charset=UTF-8
< Pragma: no-cache
< Cache-Control: no-cache
< Transfer-Encoding: chunked
<
* Connection #0 to host 172.16.1.18 left intact
* Closing connection #0


More information about the Beginners mailing list