I'm trying to write a bot pulling some data which is only available to authenticated users. I settled for ocaml (v. 3.12.1) and ocamlnet (v. 3.6.5) . The first part of the script sends a POST request to the website and by the html I receive back, I can tell that the authentication worked ( p1 and p2 's values in this code sample are obviously not the ones I'm using).

open Http_client open Nethttp let pipeline = new pipeline let () = let post_call = new post "http://www.kraland.org/main.php?p=1&a=100" [("p1", "username"); ("p2", "password"); ("Submit", "Ok!")] in pipeline#add post_call; pipeline#run();

Then I extract the cookies where the php session id, the account name, a hash of the password, etc. are stored, put them in the header of the next request and run it. And this is where I run into troubles: I systematically get the boring page every anonymous visitor gets.

let cookies = Header.get_set_cookie post_call#response_header in let get_call = new get "http://www.kraland.org/main.php?p=1" in let header = get_call#request_header `Base in Header.set_set_cookie header cookies; pipeline#add get_call; pipeline#run();

When I print the content of the cookies, I do get something weird: I would expect the domain of the cookies to be kraland.org but it does not seem to be the case. This is the printing command I use together with the output:

List.iter (fun c -> Printf.printf "%.0f [%s%s:%b] %s := %s

" (match c.cookie_expires with None -> -1. | Some f -> f) (match c.cookie_domain with None -> "" | Some s -> s) (match c.cookie_path with None -> "" | Some s -> s) c.cookie_secure c.cookie_name c.cookie_value) cookies; -1 [/:false] PHPSESSID := 410b97b0536b3e949df17edd44965926 1372719625 [:false] login := username 1372719625 [:false] id := myid 1372719625 [:false] password := fbCK/0M+blFRLx3oDp+24bHlwpDUy7x885sF+Q865ms= 1372719625 [:false] pc_id := 872176495311

Edit: I had a go at the problem using Haskell's Http-conduit-browser and it works like a charm using something very much like the doc's example.