Ocaml 如何获取 https url
Ocaml how get https url
如何将页面转为 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
如果您只想获得 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
如何将页面转为 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
如果您只想获得 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