let ok_url = "http://ocaml.org/" let fail_url = "https://www.presseportal.de/" exception Get_error of Nethttp_client.status let get url = Printf.eprintf "Url to get: %s\n%!" url; (* the Pipeline to run the call *) (* ---------------------------- *) let pipeline = new Nethttp_client.pipeline in (* the call-object - it can either be an object for GET or for POST *) (* ---------------------------------------------------------------- *) let call_obj = new Nethttp_client.get url in pipeline # add call_obj; (* add the get-call to the pipeline *) pipeline # run(); (* process the pipeline (retrieve data) *) begin (* rudimentary status-handling *) match call_obj # status with | `Client_error -> prerr_endline "Get_error: Client_error"; raise (Get_error `Client_error) | `Http_protocol_error exc -> prerr_string "Get_error: Http_protocol_error"; prerr_endline (Printexc.to_string exc); raise (Get_error (`Http_protocol_error exc)) | `Successful -> prerr_endline "Status: `Successful" | _ -> prerr_endline "Status: other" end; (call_obj # response_body # value) (* give back the web-data *) let _ = (* Initialization *) (* ============== *) Nettls_gnutls.init(); (* this is needed for https-support via gnutls-lib *) List.iter ( fun url -> Printf.printf "-----> Start with URL %s\n%!" url; let data = get url in Printf.printf "Length of data: %d\n%!" (String.length data); Printf.printf "<----- Ready with URL %s\n\n%!" url (* Printf.eprintf "WEBDATA:\n%s\n" data *) ) [ ok_url; fail_url]