4 * Copyright (c) 2003-2008, Lars Nilsson, <lars@quantumchamaleon.com>
8 let writer accum data
=
9 Buffer.add_string accum data
;
12 let showContent content
=
13 Printf.printf
"%s" (Buffer.contents content
);
16 let showInfo connection
=
17 Printf.printf
"Time: %f\nURL: %s\n"
18 (Curl.get_totaltime connection
)
19 (Curl.get_effectiveurl connection
)
21 let getContent connection url
=
22 Curl.set_url connection url
;
23 Curl.perform connection
26 Curl.global_init
Curl.CURLINIT_GLOBALALL
;
28 let result = Buffer.create
16384
29 and errorBuffer
= ref "" in
31 let connection = Curl.init
() in
32 Curl.set_errorbuffer
connection errorBuffer
;
33 Curl.set_writefunction
connection (writer result);
34 Curl.set_followlocation
connection true;
35 Curl.set_url
connection Sys.argv
.(1);
36 Curl.perform
connection;
39 Curl.cleanup
connection
41 | Curl.CurlException
(reason
, code
, str
) ->
42 Printf.fprintf stderr
"Error: %s\n" !errorBuffer
44 Printf.fprintf stderr
"Caught exception: %s\n" s
46 Curl.global_cleanup
()