/gist:0852d9aa155529b5d3cd Secret
Last active
August 29, 2015 14:03
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Open Core_kernel.Std | |
open Lwt | |
let ask_whoami username password outfile = | |
let urlstr = "https://..." in | |
let baseauth = BatBase64.str_encode ("Basic " ^ username ^ ":" ^ password) in | |
let header = Cohttp.Header.init_with "Authorization" baseauth in | |
Cohttp_lwt_unix.Client.get ~headers:header (Uri.of_string urlstr) | |
>|= fun (_, b) -> | |
match b with | |
#Cohttp.Body.t -> | |
printf "Wat"; | |
| `Stream body -> | |
Lwt_stream.to_list body | |
>|= fun li -> String.concat li | |
>|= fun str -> | |
Out_channel.write_all outfile ~data:str | |
let read_whoami infile = | |
In_channel.read_all infile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment