HTTP: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (Undo revision 315435 by WdeCvfYlmB (talk)) |
Thundergnat (talk | contribs) (Undo revision 315433 by WdeCvfYlmB (talk)) |
||
Line 832: | Line 832: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
In F# we can just use the .NET library to do this so its the same as the [[C_sharp|C#]] example. |
In F# we can just use the .NET library to do this so its the same as the [[C_sharp|C#]] example. |
||
⚫ | |||
⚫ | |||
⚫ | |||
use c = new System.Net.WebClient() |
use c = new System.Net.WebClient() |
||
c.DownloadString(url) |
c.DownloadString(url) |
||
printfn "%s" (wget "http://www. |
printfn "%s" (wget "http://www.rosettacode.org/") |
||
</lang> |
|||
However unlike C#, F# can use an asynchronous workflow to avoid blocking any threads while waiting for a response from the server. To asynchronously download three url's at once... |
However unlike C#, F# can use an asynchronous workflow to avoid blocking any threads while waiting for a response from the server. To asynchronously download three url's at once... |
||
⚫ | |||
<lang fsharp> |
|||
open System.Net |
|||
open System.IO |
open System.IO |
||
let wgetAsync url = |
let wgetAsync url = |
||
let request = WebRequest.Create (url:string) |
|||
async { let request = WebRequest.Create (url:string) |
|||
use |
use! response = request.AsyncGetResponse() |
||
use responseStream = response.GetResponseStream() |
|||
use reader = new StreamReader(responseStream) |
|||
use reader = new StreamReader(responseStream) |
|||
return reader.ReadToEnd() } |
|||
} |
|||
let urls = ["http://www.w3.org/Home.html"] |
|||
let urls = ["http://www.rosettacode.org/"; "http://www.yahoo.com/"; "http://www.google.com/"] |
|||
let content = urls |
let content = urls |
||
|> List.map wgetAsync |
|> List.map wgetAsync |
||
Line 854: | Line 862: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
<lang factor>USE: http.client |
<lang factor>USE: http.client |
||
"http://www. |
"http://www.w3.org/Home.html" http-get nip print</lang> |
||
=={{header|Forth}}== |
=={{header|Forth}}== |