FSharp.Core


WebExtensions Module

A module of extension members providing asynchronous operations for some basic Web operations.

Type extensions

Type extension Description

this.AsyncDownloadData

Full Usage: this.AsyncDownloadData

Parameters:
    address : Uri - The URI to retrieve.

Returns: Async<byte[]> An asynchronous computation that will wait for the download of the URI.

Returns an asynchronous computation that, when run, will wait for the download of the given URI.

Extended Type: WebClient

address : Uri

The URI to retrieve.

Returns: Async<byte[]>

An asynchronous computation that will wait for the download of the URI.

Example

 open System.Net
 open System.Text
 open System
 let client = new WebClient()
 client.AsyncDownloadData(Uri("https://www.w3.org")) |> Async.RunSynchronously |> Encoding.ASCII.GetString

this.AsyncDownloadFile

Full Usage: this.AsyncDownloadFile

Parameters:
    address : Uri - The URI to retrieve.
    fileName : string - The filename to save download to.

Returns: Async<unit> An asynchronous computation that will wait for the download of the URI to specified file.

Returns an asynchronous computation that, when run, will wait for the download of the given URI to specified file.

Extended Type: WebClient

address : Uri

The URI to retrieve.

fileName : string

The filename to save download to.

Returns: Async<unit>

An asynchronous computation that will wait for the download of the URI to specified file.

Example

 open System.Net
 open System
 let client = new WebClient()
 Uri("https://www.w3.com") |> fun x -> client.AsyncDownloadFile(x, "output.html") |> Async.RunSynchronously
This will download the server response as a file and output it as output.html

this.AsyncDownloadString

Full Usage: this.AsyncDownloadString

Parameters:
    address : Uri - The URI to retrieve.

Returns: Async<string> An asynchronous computation that will wait for the download of the URI.

Returns an asynchronous computation that, when run, will wait for the download of the given URI.

Extended Type: WebClient

address : Uri

The URI to retrieve.

Returns: Async<string>

An asynchronous computation that will wait for the download of the URI.

Example

 open System
 let client = new WebClient()
 Uri("https://www.w3.org") |> client.AsyncDownloadString |> Async.RunSynchronously
This will download the server response from https://www.w3.org

this.AsyncGetResponse

Full Usage: this.AsyncGetResponse

Parameters:
Returns: Async<WebResponse> An asynchronous computation that waits for response to the WebRequest.

Returns an asynchronous computation that, when run, will wait for a response to the given WebRequest.

Extended Type: WebRequest

() : unit
Returns: Async<WebResponse>

An asynchronous computation that waits for response to the WebRequest.

Example

 open System.Net
 open System.IO
 let responseStreamToString = fun (responseStream : WebResponse) ->
     let reader = new StreamReader(responseStream.GetResponseStream())
     reader.ReadToEnd()
 let webRequest = WebRequest.Create("https://www.w3.org")
 let result = webRequest.AsyncGetResponse() |> Async.RunSynchronously |> responseStreamToString