Created
January 10, 2011 03:48
-
-
Save TheDahv/772326 to your computer and use it in GitHub Desktop.
Function to get the contents of a URL asynchronously
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 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