Skip to content

Instantly share code, notes, and snippets.

@BitPuffin
Last active August 29, 2015 14:03
Show Gist options
  • Save BitPuffin/0852d9aa155529b5d3cd to your computer and use it in GitHub Desktop.
Save BitPuffin/0852d9aa155529b5d3cd to your computer and use it in GitHub Desktop.
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