Skip to content

Instantly share code, notes, and snippets.

@TheDahv
Created January 10, 2011 03:48
Show Gist options
  • Save TheDahv/772326 to your computer and use it in GitHub Desktop.
Save TheDahv/772326 to your computer and use it in GitHub Desktop.
Function to get the contents of a URL asynchronously
open System.Net
let getHttpContents (url:string) = async {
let req = WebRequest.Create(url)
let! response = req.AsyncGetResponse()
use stream = response.GetResponseStream()
use streamreader = new System.IO.StreamReader(stream)
let contents = streamreader.ReadToEnd()
return contents
}
printfn "%s" ( (getHttpContents "http://www.google.com") |> Async.RunSynchronously )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment