HTTP: Difference between revisions

Content added Content deleted
(Undo revision 315435 by WdeCvfYlmB (talk))
(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.

<lang fsharp>let wget (url : string) =
<lang fsharp>
let wget (url : string) =
use c = new System.Net.WebClient()
use c = new System.Net.WebClient()
c.DownloadString(url)
c.DownloadString(url)

printfn "%s" (wget "http://www.w3.org/Home.html")</lang>
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
<lang fsharp>
open System.Net
open System.IO
open System.IO

let wgetAsync url = async {
let wgetAsync url =
let request = WebRequest.Create (url:string)
use! response = request.AsyncGetResponse()
async { let request = WebRequest.Create (url:string)
use responseStream = response.GetResponseStream()
use! response = request.AsyncGetResponse()
use responseStream = response.GetResponseStream()
use reader = new StreamReader(responseStream)
return reader.ReadToEnd()
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.rosettacode.org" http-get nip print</lang>
"http://www.w3.org/Home.html" http-get nip print</lang>


=={{header|Forth}}==
=={{header|Forth}}==