Ocaml如何获取https url
问题描述:
如何将页面转到https?试过了。Ocaml如何获取https url
open Sys
open Array
open Str
open List
open Printf
open Unix
open Http_client.Convenience
open Nethttp
open Http_client.Convenience
open Netsys_tls;;
let provider = Netsys_tls.current_tls();;
let tls_config =
Netsys_tls.create_x509_config
~system_trust:true
~peer_auth:`Required
provider;;
let getPage _ =
let pipeline = new Http_client.pipeline in
let call = new Http_client.get ("https://vk.com/") in
call#set_redirect_mode Http_client.Do_not_redirect;
pipeline#add call;
pipeline#run();
let cookies = Header.get_set_cookie call#response_header in
List.iter (fun c -> print_string(c.cookie_name^"="^c.cookie_value^"\n")) cookies;;
getPage();;
但是当编译我得到这个错误:
Error: Unbound module Netsys_tls
c:\wodi32\opt\wodi32\bin\ocamlfind ocamlopt unix.cmxa bigarray.cmxa str.cmxa -I +labltk labltk.cmxa -I c:\wodi32\opt\wodi32\lib\ocaml\pkg-lib\netsys\ netsys_oothr.cmxa netsys.cmxa -I c:\wodi32\opt\wodi32\lib\ocaml\pkg-lib\netstring\ netstring.cmxa -I c:\wodi32\opt\wodi32\lib\ocaml\pkg-lib\equeue\ equeue.cmxa -I c:\wodi32\opt\wodi32\lib\ocaml\pkg-lib\netclient\ netclient.cmxa vk.ml -I c:\wodi32\opt\wodi32\lib\ocaml\pkg-lib\equeue-ssl\ equeue_ssl.cmxa -I c:\wodi32\opt\wodi32\lib\ocaml\pkg-lib\cryptgps\ cryptgps.cmxa -o vk.exe
我在哪里可以得到模块Netsys_tls
答
如果你只是想获得的URL,并没有其他原因坚持用OCamlnet,那么你可以使用curl
库,这将照顾所有注意事项:
let fetch fname url =
let fd = open_in fname in
let write s = Out_channel.output_string fd s; String.length s in
let conn = Curl.init() in
Curl.set_writefunction conn (write);
Curl.set_failonerror conn true;
Curl.set_followlocation conn true;
Curl.set_url conn url;
Curl.perform conn;
Curl.cleanup conn;
close_out fd
它会抓取curl支持的任何url,包括https
+0
感谢您的帮助。 – 2015-02-24 02:57:48
你的问题大多不是OCaml,而是编译。你需要链接到'Netsys_tls'模块。除非我们知道你是如何构建你的测试程序,否则我们很难给你一个建议。据我所知,你只是试图在OCaml顶层评估代码。在这种情况下,您需要发出一个'#require'libname“;;'命令,其中libname是包含此模块的库的名称。对于curl(例如,我在下面提供的例子中,正确的调用将是'#require“ocurl”;;'。对于ocamlnet,您可以尝试使用'ocamlfind list'找到名称 – ivg 2015-02-23 13:40:54