I am trying to write a bot by pulling some data that is only available to authenticated users. I settled on 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 the html that I get back can say that the authentication work ( p1 and p2 ) in this code example is obviously not the same m).
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, account name, password hash, etc. are stored, put them in the header of the next request and run it. And here I run into problems: I systematically get the boring page that every anonymous visitor receives.
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 contents of cookies, I get something strange: I would expect the cookie domain to be kraland.org , but it doesn't seem to be that way. This is the print command that I use with the output:
List.iter (fun c -> Printf.printf "%.0f [%s%s:%b] %s := %s\n" (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 problem using the Haskell Http-conduit browser and it works like a charm, using something very similar to the doc example .
source share