1234567891011121314151617181920212223 |
- open System.Net
- open System
- open System.IO
-
- let fetchUrl cb url =
- let req = WebRequest.Create(Uri(url))
- use resp = req.GetResponse()
- use stream = resp.GetResponseStream()
- use reader = new IO.StreamReader(stream)
- cb reader url
-
- let myCb (reader:IO.StreamReader) url =
- let html = reader.ReadToEnd()
- let html1000 = html.Substring(0,1000)
- printfn "Downloaded %s. First 1000 is %s" url html1000
- html
-
- // let blog = fetchUrl myCb "https://blog.etopiei.com"
- // This could also be written `point free` but I like the explicitness
- let generalPageDownload url = fetchUrl myCb url
-
- generalPageDownload "https://google.com"
- generalPageDownload "https://etopiei.com"
|