Michael Orlitzky | 29 Jun 04:32 2012

Network.Curl curiosity

I've been fighting with this silly bug: I have two functions using curl
(Network.Curl) for logging in via POST and downloading pages via GET.
They do the usual boring stuff; cookies go in a text file whose path is
passed in to both functions. They work great individually.

But, I'm calling them sequentially:

  cj <- make_cookie_jar
  li_result <- log_in cj username password
  html <- get_page (Just cj) my_article

The symptom that I noticed was that the call to get_page wasn't using
the cookies. I looked in the cookie file -- they're all there. And when
I call get_page from ghci (with the same cookie file), it works.

It turns out that between the calls to log_in and get_page, the cookie
file is empty. The stupidest possible solution that works is,

  cj <- make_cookie_jar
  li_result <- log_in cj username password

  putStrLn "Waiting one second..."
  thread_sleep 1

  html <- get_page (Just cj) my_article

And this program is not at all time sensitive, so that actually works
for me. But now I'm curious. Does anyone have an idea what sort of
sorcery is going on?

(Continue reading)


Gmane