如何将网页设为https?试过了。
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
答案 0 :(得分:0)
如果您只想获取网址,并且没有其他理由坚持使用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支持的任何网址,包括https