HTTP: Difference between revisions
Content added Content deleted
m (Emacs Lisp: Fix formatting) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 9: | Line 9: | ||
=={{header|8th}}== |
=={{header|8th}}== |
||
< |
<syntaxhighlight lang="forth"> |
||
"http://www.rosettacode.org" net:get drop >s . |
"http://www.rosettacode.org" net:get drop >s . |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|ABAP}}== |
=={{header|ABAP}}== |
||
This works for ABAP Version 7.40 and above |
This works for ABAP Version 7.40 and above |
||
<syntaxhighlight lang="abap"> |
|||
<lang ABAP> |
|||
report z_http. |
report z_http. |
||
Line 51: | Line 51: | ||
write / <output_line>. |
write / <output_line>. |
||
endloop. |
endloop. |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 67: | Line 67: | ||
=={{header|ActionScript}}== |
=={{header|ActionScript}}== |
||
< |
<syntaxhighlight lang="actionscript"> |
||
package |
package |
||
{ |
{ |
||
Line 89: | Line 89: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{libheader|AWS}} |
{{libheader|AWS}} |
||
< |
<syntaxhighlight lang="ada"> |
||
with Ada.Text_IO; use Ada.Text_IO; |
with Ada.Text_IO; use Ada.Text_IO; |
||
Line 103: | Line 103: | ||
Put_Line (AWS.Response.Message_Body (AWS.Client.Get (URL => "http://www.rosettacode.org"))); |
Put_Line (AWS.Response.Message_Body (AWS.Client.Get (URL => "http://www.rosettacode.org"))); |
||
end HTTP_Request; |
end HTTP_Request; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
Line 111: | Line 111: | ||
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of ''grep in string'' and ''http content''}} |
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of ''grep in string'' and ''http content''}} |
||
< |
<syntaxhighlight lang="algol68"> |
||
STRING domain="rosettacode.org"; |
STRING domain="rosettacode.org"; |
||
STRING page="wiki/Main_Page"; |
STRING page="wiki/Main_Page"; |
||
Line 141: | Line 141: | ||
ELSE print (strerror (rc)) |
ELSE print (strerror (rc)) |
||
FI |
FI |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Amazing Hopper}}== |
=={{header|Amazing Hopper}}== |
||
<syntaxhighlight lang="amazing hopper"> |
|||
<lang Amazing Hopper> |
|||
#include <hopper.h> |
#include <hopper.h> |
||
main: |
main: |
||
Line 150: | Line 150: | ||
{"Size = ",lenght,"\nContent = \n",s}println |
{"Size = ",lenght,"\nContent = \n",s}println |
||
exit(0) |
exit(0) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 164: | Line 164: | ||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">print read "http://rosettacode.org"</syntaxhighlight> |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
<syntaxhighlight lang="autohotkey"> |
|||
<lang AutoHotkey> |
|||
UrlDownloadToFile, http://rosettacode.org, url.html |
UrlDownloadToFile, http://rosettacode.org, url.html |
||
Run, cmd /k type url.html |
Run, cmd /k type url.html |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
{{works with|gawk}} |
{{works with|gawk}} |
||
< |
<syntaxhighlight lang="awk">BEGIN { |
||
site="en.wikipedia.org" |
site="en.wikipedia.org" |
||
path="/wiki/" |
path="/wiki/" |
||
Line 193: | Line 193: | ||
print ship |
print ship |
||
}</ |
}</syntaxhighlight> |
||
=={{header|BaCon}}== |
=={{header|BaCon}}== |
||
< |
<syntaxhighlight lang="qbasic">' |
||
' Read and display a website |
' Read and display a website |
||
' |
' |
||
Line 213: | Line 213: | ||
CLOSE NETWORK mynet |
CLOSE NETWORK mynet |
||
PRINT total$ |
PRINT total$ |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Batch File}}== |
=={{header|Batch File}}== |
||
< |
<syntaxhighlight lang="batch"> |
||
curl.exe -s -L http://rosettacode.org/ |
curl.exe -s -L http://rosettacode.org/ |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
{{works with|BBC BASIC for Windows}} |
{{works with|BBC BASIC for Windows}} |
||
< |
<syntaxhighlight lang="bbcbasic"> SYS "LoadLibrary", "URLMON.DLL" TO urlmon% |
||
SYS "GetProcAddress", urlmon%, "URLDownloadToFileA" TO URLDownloadToFile |
SYS "GetProcAddress", urlmon%, "URLDownloadToFileA" TO URLDownloadToFile |
||
Line 230: | Line 230: | ||
IF fail% ERROR 100, "File download failed" |
IF fail% ERROR 100, "File download failed" |
||
OSCLI "TYPE """ + file$ + """"</ |
OSCLI "TYPE """ + file$ + """"</syntaxhighlight> |
||
=={{header|Biferno}}== |
=={{header|Biferno}}== |
||
simple one-liner using httpExt and quick print $ |
simple one-liner using httpExt and quick print $ |
||
< |
<syntaxhighlight lang="biferno">$httpExt.ExecRemote("www.tabasoft.it")</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
{{libheader|libcurl}} |
{{libheader|libcurl}} |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
#include <stdio.h> |
#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
Line 262: | Line 262: | ||
return EXIT_SUCCESS; |
return EXIT_SUCCESS; |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|C sharp}}== |
=={{header|C sharp}}== |
||
< |
<syntaxhighlight lang="csharp"> |
||
using System; |
using System; |
||
using System.Text; |
using System.Text; |
||
Line 279: | Line 279: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp"> |
||
#include <winsock2.h> |
#include <winsock2.h> |
||
#include <ws2tcpip.h> |
#include <ws2tcpip.h> |
||
Line 321: | Line 321: | ||
return 0; |
return 0; |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{libheader|U++}} |
{{libheader|U++}} |
||
< |
<syntaxhighlight lang="cpp"> |
||
#include <Web/Web.h> |
#include <Web/Web.h> |
||
Line 334: | Line 334: | ||
Cout() << HttpClient("www.rosettacode.org").ExecuteRedirect(); |
Cout() << HttpClient("www.rosettacode.org").ExecuteRedirect(); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Caché ObjectScript}}== |
=={{header|Caché ObjectScript}}== |
||
Line 347: | Line 347: | ||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
Using the Java API: |
Using the Java API: |
||
< |
<syntaxhighlight lang="clojure"> |
||
(defn get-http [url] |
(defn get-http [url] |
||
(let [sc (java.util.Scanner. |
(let [sc (java.util.Scanner. |
||
Line 354: | Line 354: | ||
(println (.nextLine sc))))) |
(println (.nextLine sc))))) |
||
(get-http "http://www.rosettacode.org") |
(get-http "http://www.rosettacode.org") |
||
</syntaxhighlight> |
|||
</lang> |
|||
Using <code>clojure.contrib.http.agent</code>: |
Using <code>clojure.contrib.http.agent</code>: |
||
< |
<syntaxhighlight lang="clojure"> |
||
(ns example |
(ns example |
||
(:use [clojure.contrib.http.agent :only (string http-agent)])) |
(:use [clojure.contrib.http.agent :only (string http-agent)])) |
||
(println (string (http-agent "http://www.rosettacode.org/"))) |
(println (string (http-agent "http://www.rosettacode.org/"))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{works with|Clojure|1.2}} |
{{works with|Clojure|1.2}} |
||
< |
<syntaxhighlight lang="clojure"> |
||
(print (slurp "http://www.rosettacode.org/")) |
(print (slurp "http://www.rosettacode.org/")) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
Line 373: | Line 373: | ||
Tested with GnuCOBOL |
Tested with GnuCOBOL |
||
< |
<syntaxhighlight lang="cobol">COBOL >>SOURCE FORMAT IS FIXED |
||
identification division. |
identification division. |
||
program-id. curl-rosetta. |
program-id. curl-rosetta. |
||
Line 664: | Line 664: | ||
goback. |
goback. |
||
end program curl-write-callback.</ |
end program curl-write-callback.</syntaxhighlight> |
||
and a copybook |
and a copybook |
||
< |
<syntaxhighlight lang="cobol"> *> manifest constants for libcurl |
||
*> Usage: COPY occurlsym inside data division |
*> Usage: COPY occurlsym inside data division |
||
*> Taken from include/curl/curl.h 2013-12-19 |
*> Taken from include/curl/curl.h 2013-12-19 |
||
Line 859: | Line 859: | ||
03 FILLER PIC X(30) VALUE "CURLE_AGAIN ". |
03 FILLER PIC X(30) VALUE "CURLE_AGAIN ". |
||
01 FILLER REDEFINES LIBCURL_ERRORS. |
01 FILLER REDEFINES LIBCURL_ERRORS. |
||
02 CURLEMSG OCCURS 81 TIMES PIC X(30).</ |
02 CURLEMSG OCCURS 81 TIMES PIC X(30).</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 874: | Line 874: | ||
=={{header|ColdFusion}}== |
=={{header|ColdFusion}}== |
||
< |
<syntaxhighlight lang="coldfusion"> |
||
<cfhttp url="http://www.rosettacode.org" result="result"> |
<cfhttp url="http://www.rosettacode.org" result="result"> |
||
<cfoutput>#result.FileContent#</cfoutput> |
<cfoutput>#result.FileContent#</cfoutput> |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
CLISP provides an extension function to read http sources. Other implementations may do this differently. |
CLISP provides an extension function to read http sources. Other implementations may do this differently. |
||
{{works with|CLISP}} |
{{works with|CLISP}} |
||
< |
<syntaxhighlight lang="lisp"> |
||
(defun wget-clisp (url) |
(defun wget-clisp (url) |
||
(ext:with-http-input (stream url) |
(ext:with-http-input (stream url) |
||
Line 888: | Line 888: | ||
while line |
while line |
||
do (format t "~a~%" line)))) |
do (format t "~a~%" line)))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{libheader|DRAKMA}} |
{{libheader|DRAKMA}} |
||
Line 894: | Line 894: | ||
First grabbing the entire body as a string, and then by pulling from a stream (as in the CLISP example). |
First grabbing the entire body as a string, and then by pulling from a stream (as in the CLISP example). |
||
< |
<syntaxhighlight lang="lisp"> |
||
(defun wget-drakma-string (url &optional (out *standard-output*)) |
(defun wget-drakma-string (url &optional (out *standard-output*)) |
||
"Grab the body as a string, and write it to out." |
"Grab the body as a string, and write it to out." |
||
Line 905: | Line 905: | ||
while line do (write-line line out) |
while line do (write-line line out) |
||
finally (close body))) |
finally (close body))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{libheader|Dexador}} |
{{libheader|Dexador}} |
||
< |
<syntaxhighlight lang="lisp"> |
||
(format t "~a~%" (nth-value 0 (dex:get "http://www.w3.org/"))) |
(format t "~a~%" (nth-value 0 (dex:get "http://www.w3.org/"))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Crystal}}== |
=={{header|Crystal}}== |
||
< |
<syntaxhighlight lang="crystal"> |
||
require "http/client" |
require "http/client" |
||
HTTP::Client.get("http://google.com") |
HTTP::Client.get("http://google.com") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
{{libheader|phobos}} |
{{libheader|phobos}} |
||
<syntaxhighlight lang="d"> |
|||
<lang D> |
|||
void main() { |
void main() { |
||
import std.stdio, std.net.curl; |
import std.stdio, std.net.curl; |
||
writeln(get("http://google.com")); |
writeln(get("http://google.com")); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{libheader|tango}} |
{{libheader|tango}} |
||
<syntaxhighlight lang="d"> |
|||
<lang D> |
|||
import tango.io.Console; |
import tango.io.Console; |
||
import tango.net.http.HttpGet; |
import tango.net.http.HttpGet; |
||
Line 938: | Line 938: | ||
Cout.stream.copy( (new HttpGet("http://google.com")).open ); |
Cout.stream.copy( (new HttpGet("http://google.com")).open ); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Or more operating directly on the socket: |
Or more operating directly on the socket: |
||
<syntaxhighlight lang="d"> |
|||
<lang D> |
|||
import tango.io.Console; |
import tango.io.Console; |
||
import tango.net.InternetAddress; |
import tango.net.InternetAddress; |
||
Line 953: | Line 953: | ||
Cout.stream.copy (site); |
Cout.stream.copy (site); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Dart}}== |
=={{header|Dart}}== |
||
Using the stand-alone VM: |
Using the stand-alone VM: |
||
< |
<syntaxhighlight lang="d">import 'dart:io'; |
||
void main(){ |
void main(){ |
||
var url = 'http://rosettacode.org'; |
var url = 'http://rosettacode.org'; |
||
Line 964: | Line 964: | ||
.then((HttpClientRequest request) => request.close()) |
.then((HttpClientRequest request) => request.close()) |
||
.then((HttpClientResponse response) => response.pipe(stdout)); |
.then((HttpClientResponse response) => response.pipe(stdout)); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
Simple example using the free Synapse TCP/IP library [http://www.ararat.cz/synapse/doku.php/download] |
Simple example using the free Synapse TCP/IP library [http://www.ararat.cz/synapse/doku.php/download] |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
program HTTP; |
program HTTP; |
||
Line 1,013: | Line 1,013: | ||
end. |
end. |
||
</syntaxhighlight> |
|||
</lang> |
|||
Using Indy: |
Using Indy: |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
program ShowHTTP; |
program ShowHTTP; |
||
Line 1,038: | Line 1,038: | ||
end; |
end; |
||
end. |
end. |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Dragon}}== |
=={{header|Dragon}}== |
||
< |
<syntaxhighlight lang="dragon">select "http" |
||
select "std" |
select "std" |
||
http("http://www.rosettacode.org", ::echo) |
http("http://www.rosettacode.org", ::echo) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|E}}== |
=={{header|E}}== |
||
<syntaxhighlight lang="e"> |
|||
<lang e> |
|||
when (def t := <http://www.rosettacode.org> <- getText()) -> { |
when (def t := <http://www.rosettacode.org> <- getText()) -> { |
||
println(t) |
println(t) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|EchoLisp}}== |
=={{header|EchoLisp}}== |
||
'''file->string''' usage: the server must allow cross-domain access, or a browser add-on like cors-everywhere must be installed to bypass cross-domain checking. |
'''file->string''' usage: the server must allow cross-domain access, or a browser add-on like cors-everywhere must be installed to bypass cross-domain checking. |
||
< |
<syntaxhighlight lang="scheme"> |
||
;; asynchronous call back definition |
;; asynchronous call back definition |
||
(define (success name text) (writeln 'Loaded name) (writeln text)) |
(define (success name text) (writeln 'Loaded name) (writeln text)) |
||
;; |
;; |
||
(file->string success "http://www.google.com") |
(file->string success "http://www.google.com") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |
||
Line 1,071: | Line 1,071: | ||
<code>url-retrieve-synchronously</code> returns a buffer containing headers and body. Caller must kill the buffer when no longer needed. |
<code>url-retrieve-synchronously</code> returns a buffer containing headers and body. Caller must kill the buffer when no longer needed. |
||
< |
<syntaxhighlight lang="lisp">(let ((buffer (url-retrieve-synchronously "http://www.rosettacode.org"))) |
||
(unwind-protect |
(unwind-protect |
||
(with-current-buffer buffer |
(with-current-buffer buffer |
||
(message "%s" (buffer-substring url-http-end-of-headers (point-max)))) |
(message "%s" (buffer-substring url-http-end-of-headers (point-max)))) |
||
(kill-buffer buffer)))</ |
(kill-buffer buffer)))</syntaxhighlight> |
||
Asynchronously (buffer doesn't need to be killed by caller): |
Asynchronously (buffer doesn't need to be killed by caller): |
||
< |
<syntaxhighlight lang="lisp">(url-retrieve "http://www.rosettacode.org" |
||
(lambda (_status) |
(lambda (_status) |
||
(message "%s" (buffer-substring url-http-end-of-headers (point-max)))))</ |
(message "%s" (buffer-substring url-http-end-of-headers (point-max)))))</syntaxhighlight> |
||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
===Synchronous=== |
===Synchronous=== |
||
< |
<syntaxhighlight lang="erlang"> |
||
-module(main). |
-module(main). |
||
-export([main/1]). |
-export([main/1]). |
||
Line 1,095: | Line 1,095: | ||
{error, Res} -> io:fwrite("~p~n", [Res]) |
{error, Res} -> io:fwrite("~p~n", [Res]) |
||
end. |
end. |
||
</syntaxhighlight> |
|||
</lang> |
|||
===Asynchronous=== |
===Asynchronous=== |
||
< |
<syntaxhighlight lang="erlang"> |
||
-module(main). |
-module(main). |
||
-export([main/1]). |
-export([main/1]). |
||
Line 1,110: | Line 1,110: | ||
after 10000 -> io:fwrite("Timed out.~n",[]) |
after 10000 -> io:fwrite("Timed out.~n",[]) |
||
end. |
end. |
||
</syntaxhighlight> |
|||
</lang> |
|||
Using it |
Using it |
||
< |
<syntaxhighlight lang="erlang"> |
||
|escript ./req.erl http://www.rosettacode.org |
|escript ./req.erl http://www.rosettacode.org |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{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. |
||
< |
<syntaxhighlight lang="fsharp"> |
||
let wget (url : string) = |
let wget (url : string) = |
||
use c = new System.Net.WebClient() |
use c = new System.Net.WebClient() |
||
Line 1,126: | Line 1,126: | ||
printfn "%s" (wget "http://www.rosettacode.org/") |
printfn "%s" (wget "http://www.rosettacode.org/") |
||
</syntaxhighlight> |
|||
</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... |
||
< |
<syntaxhighlight lang="fsharp"> |
||
open System.Net |
open System.Net |
||
open System.IO |
open System.IO |
||
Line 1,145: | Line 1,145: | ||
|> List.map wgetAsync |
|> List.map wgetAsync |
||
|> Async.Parallel |
|> Async.Parallel |
||
|> Async.RunSynchronously</ |
|> Async.RunSynchronously</syntaxhighlight> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USE: http.client |
||
"http://www.rosettacode.org" http-get nip print |
"http://www.rosettacode.org" http-get nip print |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|GNU Forth|0.7.0}} |
{{works with|GNU Forth|0.7.0}} |
||
This works at the socket level, returning both the HTTP headers and page contents. |
This works at the socket level, returning both the HTTP headers and page contents. |
||
< |
<syntaxhighlight lang="forth"> |
||
include unix/socket.fs |
include unix/socket.fs |
||
Line 1,162: | Line 1,162: | ||
dup pad 8092 read-socket type |
dup pad 8092 read-socket type |
||
close-socket |
close-socket |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic">Dim As String urlfile |
||
urlfile="start http://rosettacode.org/wiki/Main_Page" |
urlfile="start http://rosettacode.org/wiki/Main_Page" |
||
Line 1,174: | Line 1,174: | ||
Print !"\n--- pulsa RETURN para continuar ---" |
Print !"\n--- pulsa RETURN para continuar ---" |
||
Sleep</ |
Sleep</syntaxhighlight> |
||
=={{header|friendly interactive shell}}== |
=={{header|friendly interactive shell}}== |
||
{{trans|UNIX Shell}} |
{{trans|UNIX Shell}} |
||
< |
<syntaxhighlight lang="fishshell">curl -s -L http://rosettacode.org/</syntaxhighlight> |
||
< |
<syntaxhighlight lang="fishshell">lynx -source http://rosettacode.org/</syntaxhighlight> |
||
< |
<syntaxhighlight lang="fishshell">wget -O - -q http://rosettacode.org/</syntaxhighlight> |
||
< |
<syntaxhighlight lang="fishshell">lftp -c "cat http://rosettacode.org/"</syntaxhighlight> |
||
{{works with|BSD}} |
{{works with|BSD}} |
||
< |
<syntaxhighlight lang="fishshell">ftp -o - http://rosettacode.org ^ /dev/null</syntaxhighlight> |
||
=={{header|Frink}}== |
=={{header|Frink}}== |
||
Frink's <CODE>read[<I>URL</I>]</CODE> function works with any URL type supported by your Java Virtual Machine, and returns the results as a single string. |
Frink's <CODE>read[<I>URL</I>]</CODE> function works with any URL type supported by your Java Virtual Machine, and returns the results as a single string. |
||
< |
<syntaxhighlight lang="frink"> |
||
print[read["http://frinklang.org/"]] |
print[read["http://frinklang.org/"]] |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Gastona}}== |
=={{header|Gastona}}== |
||
< |
<syntaxhighlight lang="gastona">#listix# |
||
<main> |
<main> |
||
LOOP, TEXT FILE, http://www.rosettacode.org |
LOOP, TEXT FILE, http://www.rosettacode.org |
||
, BODY, @<value> |
, BODY, @<value> |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|GML}}== |
=={{header|GML}}== |
||
Line 1,208: | Line 1,208: | ||
'''Any Event''' |
'''Any Event''' |
||
< |
<syntaxhighlight lang="gml">get = http_get("http://www.rosettacode.org/");</syntaxhighlight> |
||
'''HTTP Event''' |
'''HTTP Event''' |
||
< |
<syntaxhighlight lang="gml">if (ds_map_find_value(async_load,"id") == get) |
||
{ |
{ |
||
show_message_async(ds_map_find_value(async_load,"result")); |
show_message_async(ds_map_find_value(async_load,"result")); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
<syntaxhighlight lang="go"> |
|||
<lang go> |
|||
package main |
package main |
||
Line 1,234: | Line 1,234: | ||
io.Copy(os.Stdout, r.Body) |
io.Copy(os.Stdout, r.Body) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
Line 1,248: | Line 1,248: | ||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
< |
<syntaxhighlight lang="groovy"> |
||
new URL("http://www.rosettacode.org").eachLine { println it } |
new URL("http://www.rosettacode.org").eachLine { println it } |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|GUISS}}== |
=={{header|GUISS}}== |
||
Line 1,256: | Line 1,256: | ||
It would be more appropriate to paste to notepad: |
It would be more appropriate to paste to notepad: |
||
< |
<syntaxhighlight lang="guiss">Start,Programs,Applications,Mozilla Firefox,Inputbox:address bar>www.rosettacode.org,Button:Go, |
||
Click:Area:browser window,Type:[Control A],[Control C],Start,Programs,Accessories,Notepad, |
Click:Area:browser window,Type:[Control A],[Control C],Start,Programs,Accessories,Notepad, |
||
Menu:Edit,Paste</ |
Menu:Edit,Paste</syntaxhighlight> |
||
=={{header|Halon}}== |
=={{header|Halon}}== |
||
< |
<syntaxhighlight lang="halon">echo http("http://www.rosettacode.org");</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
Using {{libheader|HTTP}} from [http://hackage.haskell.org/packages/hackage.html HackageDB] |
Using {{libheader|HTTP}} from [http://hackage.haskell.org/packages/hackage.html HackageDB] |
||
< |
<syntaxhighlight lang="haskell"> |
||
import Network.Browser |
import Network.Browser |
||
import Network.HTTP |
import Network.HTTP |
||
Line 1,277: | Line 1,277: | ||
request $ getRequest "http://www.rosettacode.org/" |
request $ getRequest "http://www.rosettacode.org/" |
||
putStrLn $ rspBody $ snd rsp |
putStrLn $ rspBody $ snd rsp |
||
</syntaxhighlight> |
|||
</lang> |
|||
== Icon and Unicon == |
== Icon and Unicon == |
||
==={{header|Icon}}=== |
==={{header|Icon}}=== |
||
< |
<syntaxhighlight lang="icon"> |
||
link cfunc |
link cfunc |
||
procedure main(arglist) |
procedure main(arglist) |
||
Line 1,301: | Line 1,301: | ||
while write(read(f)) |
while write(read(f)) |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
Using it |
Using it |
||
< |
<syntaxhighlight lang="icon"> |
||
|icon req.icn http://www.rosettacode.org |
|icon req.icn http://www.rosettacode.org |
||
</syntaxhighlight> |
|||
</lang> |
|||
==={{header|Unicon}}=== |
==={{header|Unicon}}=== |
||
Unicon provides improved socket and messaging support without the need for the external function ''cfunc'': |
Unicon provides improved socket and messaging support without the need for the external function ''cfunc'': |
||
< |
<syntaxhighlight lang="unicon"> |
||
procedure main(arglist) |
procedure main(arglist) |
||
m := open(arglist[1],"m") |
m := open(arglist[1],"m") |
||
while write(read(m)) |
while write(read(m)) |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|J}}== |
=={{header|J}}== |
||
Using <tt>gethttp</tt> from [[Web Scraping#J|Web Scraping]] |
Using <tt>gethttp</tt> from [[Web Scraping#J|Web Scraping]] |
||
< |
<syntaxhighlight lang="j">require'web/gethttp' |
||
gethttp 'http://www.rosettacode.org' |
gethttp 'http://www.rosettacode.org' |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
Using the standard [http://openjdk.java.net/groups/net/httpclient/ Java 11 HTTP Client] |
Using the standard [http://openjdk.java.net/groups/net/httpclient/ Java 11 HTTP Client] |
||
< |
<syntaxhighlight lang="java">import java.net.URI; |
||
import java.net.http.HttpClient; |
import java.net.http.HttpClient; |
||
import java.net.http.HttpRequest; |
import java.net.http.HttpRequest; |
||
Line 1,345: | Line 1,345: | ||
.join(); |
.join(); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{libheader|Apache Commons IO}} |
{{libheader|Apache Commons IO}} |
||
< |
<syntaxhighlight lang="java5"> |
||
import org.apache.commons.io.IOUtils; |
import org.apache.commons.io.IOUtils; |
||
import java.net.URL; |
import java.net.URL; |
||
Line 1,357: | Line 1,357: | ||
IOUtils.copy(new URL("http://rosettacode.org").openStream(),System.out); |
IOUtils.copy(new URL("http://rosettacode.org").openStream(),System.out); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
===Browser=== |
===Browser=== |
||
< |
<syntaxhighlight lang="javascript">var req = new XMLHttpRequest(); |
||
req.onload = function() { |
req.onload = function() { |
||
console.log(this.responseText); |
console.log(this.responseText); |
||
Line 1,368: | Line 1,368: | ||
req.open('get', 'http://rosettacode.org', true); |
req.open('get', 'http://rosettacode.org', true); |
||
req.send()</ |
req.send()</syntaxhighlight> |
||
Using fetch API: |
Using fetch API: |
||
<syntaxhighlight lang="javascript"> |
|||
<lang JavaScript> |
|||
fetch('http://rosettacode.org').then(function(response) { |
fetch('http://rosettacode.org').then(function(response) { |
||
return response.text(); |
return response.text(); |
||
Line 1,377: | Line 1,377: | ||
console.log(myText); |
console.log(myText); |
||
}); |
}); |
||
</syntaxhighlight> |
|||
</lang> |
|||
As a repeatable function: |
As a repeatable function: |
||
<syntaxhighlight lang="javascript">/** |
|||
<lang JavaScript>/** |
|||
* @name _http |
* @name _http |
||
* @description Generic API Client using XMLHttpRequest |
* @description Generic API Client using XMLHttpRequest |
||
Line 1,445: | Line 1,445: | ||
.join("&") |
.join("&") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
Using jQuery: |
Using jQuery: |
||
< |
<syntaxhighlight lang="javascript">$.get('http://rosettacode.org', function(data) { |
||
console.log(data); |
console.log(data); |
||
};</ |
};</syntaxhighlight> |
||
===Node.js=== |
===Node.js=== |
||
Line 1,457: | Line 1,457: | ||
With Node.js, using only the included http module. |
With Node.js, using only the included http module. |
||
< |
<syntaxhighlight lang="javascript">const http = require('http'); |
||
http.get('http://rosettacode.org', (resp) => { |
http.get('http://rosettacode.org', (resp) => { |
||
Line 1,475: | Line 1,475: | ||
}).on("error", (err) => { |
}).on("error", (err) => { |
||
console.log("Error: " + err.message); |
console.log("Error: " + err.message); |
||
});</ |
});</syntaxhighlight> |
||
=={{header|Jsish}}== |
=={{header|Jsish}}== |
||
Based on Jsi_Wget that ships with Jsish. |
Based on Jsi_Wget that ships with Jsish. |
||
< |
<syntaxhighlight lang="javascript">#!/usr/bin/env jsish |
||
function httpGet(fileargs:array|string, conf:object=void) { |
function httpGet(fileargs:array|string, conf:object=void) { |
||
Line 1,587: | Line 1,587: | ||
if (isMain()) |
if (isMain()) |
||
runModule(httpGet);</ |
runModule(httpGet);</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,608: | Line 1,608: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">readurl(url) = open(readlines, download(url)) |
||
readurl("http://rosettacode.org/index.html")</ |
readurl("http://rosettacode.org/index.html")</syntaxhighlight> |
||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
< |
<syntaxhighlight lang="scala">// version 1.1.2 |
||
import java.net.URL |
import java.net.URL |
||
Line 1,625: | Line 1,625: | ||
while (sc.hasNextLine()) println(sc.nextLine()) |
while (sc.hasNextLine()) println(sc.nextLine()) |
||
sc.close() |
sc.close() |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
incude_url is a wrapper for Lasso's curl datatype, however it can be achieved in several ways. |
incude_url is a wrapper for Lasso's curl datatype, however it can be achieved in several ways. |
||
< |
<syntaxhighlight lang="lasso">// using include_url wrapper: |
||
include_url('http://rosettacode.org/index.html') |
include_url('http://rosettacode.org/index.html') |
||
Line 1,638: | Line 1,638: | ||
local(x = curl('http://rosettacode.org/index')) |
local(x = curl('http://rosettacode.org/index')) |
||
local(y = #x->result) |
local(y = #x->result) |
||
#y->asString</ |
#y->asString</syntaxhighlight> |
||
=={{header|LFE}}== |
=={{header|LFE}}== |
||
===Synchronous=== |
===Synchronous=== |
||
< |
<syntaxhighlight lang="lisp">(: inets start) |
||
(case (: httpc request '"http://lfe.github.io") |
(case (: httpc request '"http://lfe.github.io") |
||
((tuple 'ok result) |
((tuple 'ok result) |
||
Line 1,649: | Line 1,649: | ||
((tuple 'error reason) |
((tuple 'error reason) |
||
(: io format '"Error: ~p~n" (list reason)))) |
(: io format '"Error: ~p~n" (list reason)))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
===Asynchronous=== |
===Asynchronous=== |
||
< |
<syntaxhighlight lang="lisp">(: inets start) |
||
(let* ((method 'get) |
(let* ((method 'get) |
||
(url '"http://lfe.github.io") |
(url '"http://lfe.github.io") |
||
Line 1,665: | Line 1,665: | ||
((tuple 'http (tuple request-id result)) |
((tuple 'http (tuple request-id result)) |
||
(: io format '"Result: ~p~n" (list result)))))) |
(: io format '"Result: ~p~n" (list result)))))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |
||
Uses a dll call and a timer to allow time to receive the file. |
Uses a dll call and a timer to allow time to receive the file. |
||
<syntaxhighlight lang="lb"> |
|||
<lang lb> |
|||
result = DownloadToFile( "http://rosettacode.org/wiki/Main_Page", "in.html") |
result = DownloadToFile( "http://rosettacode.org/wiki/Main_Page", "in.html") |
||
timer 2000, [on] |
timer 2000, [on] |
||
Line 1,690: | Line 1,690: | ||
close #url |
close #url |
||
end function |
end function |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Lingo}}== |
=={{header|Lingo}}== |
||
Line 1,696: | Line 1,696: | ||
Parent script "SimpleHttpGet": |
Parent script "SimpleHttpGet": |
||
< |
<syntaxhighlight lang="lingo">property _netID |
||
property _cbHandler |
property _cbHandler |
||
property _cbTarget |
property _cbTarget |
||
Line 1,725: | Line 1,725: | ||
call(me._cbHandler, me._cbTarget, res, err) |
call(me._cbHandler, me._cbTarget, res, err) |
||
end if |
end if |
||
end</ |
end</syntaxhighlight> |
||
In some movie script: |
In some movie script: |
||
< |
<syntaxhighlight lang="lingo">---------------------------------------- |
||
-- |
-- |
||
---------------------------------------- |
---------------------------------------- |
||
Line 1,744: | Line 1,744: | ||
put "Network Error:" && err |
put "Network Error:" && err |
||
end if |
end if |
||
end</ |
end</syntaxhighlight> |
||
Executed in the "Message Window" (=Director's interactive Lingo console): |
Executed in the "Message Window" (=Director's interactive Lingo console): |
||
< |
<syntaxhighlight lang="lingo">getAdobeHomePage() |
||
-- "<!doctype html> |
-- "<!doctype html> |
||
...</ |
...</syntaxhighlight> |
||
=={{header|LiveCode}}== |
=={{header|LiveCode}}== |
||
Without a callback handler the get URL method will block until complete |
Without a callback handler the get URL method will block until complete |
||
< |
<syntaxhighlight lang="livecode">put true into libURLFollowHttpRedirects |
||
get URL "http://httpbin.org/html" |
get URL "http://httpbin.org/html" |
||
put it</ |
put it</syntaxhighlight> |
||
Non-blocking version |
Non-blocking version |
||
< |
<syntaxhighlight lang="livecode">on myUrlDownloadFinished |
||
answer "Download Complete" with "Okay" |
answer "Download Complete" with "Okay" |
||
end myUrlDownloadFinished |
end myUrlDownloadFinished |
||
Line 1,763: | Line 1,763: | ||
command getWebResource |
command getWebResource |
||
load URL "http://httpbin.org/html" with message "myUrlDownloadFinished" |
load URL "http://httpbin.org/html" with message "myUrlDownloadFinished" |
||
end getWebResource</ |
end getWebResource</syntaxhighlight> |
||
=={{header|LSL}}== |
=={{header|LSL}}== |
||
To test it yourself; rez a box on the ground, and add the following as a New Script. |
To test it yourself; rez a box on the ground, and add the following as a New Script. |
||
< |
<syntaxhighlight lang="lsl">string sURL = "http://www.RosettaCode.Org"; |
||
key kHttpRequestId; |
key kHttpRequestId; |
||
default { |
default { |
||
Line 1,787: | Line 1,787: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre>Status=200 |
<pre>Status=200 |
||
Line 1,812: | Line 1,812: | ||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
{{libheader|LuaSocket}} |
{{libheader|LuaSocket}} |
||
<syntaxhighlight lang="lua"> |
|||
<lang Lua> |
|||
local http = require("socket.http") |
local http = require("socket.http") |
||
local url = require("socket.url") |
local url = require("socket.url") |
||
local page = http.request('http://www.google.com/m/search?q=' .. url.escape("lua")) |
local page = http.request('http://www.google.com/m/search?q=' .. url.escape("lua")) |
||
print(page) |
print(page) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
Line 1,826: | Line 1,826: | ||
(some of them as read only) |
(some of them as read only) |
||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
Module CheckIt { |
Module CheckIt { |
||
Declare xml "Microsoft.XMLHTTP" |
Declare xml "Microsoft.XMLHTTP" |
||
Line 1,856: | Line 1,856: | ||
} |
} |
||
CheckIt |
CheckIt |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
In Maple 18 or later: |
In Maple 18 or later: |
||
<syntaxhighlight lang="maple"> |
|||
<lang Maple> |
|||
content := URL:-Get( "http://www.google.com/" ); |
content := URL:-Get( "http://www.google.com/" ); |
||
</syntaxhighlight> |
|||
</lang> |
|||
In Maple 17 or earlier: |
In Maple 17 or earlier: |
||
<syntaxhighlight lang="maple"> |
|||
<lang Maple> |
|||
content := HTTP:-Get( "http://www.google.com/" ); |
content := HTTP:-Get( "http://www.google.com/" ); |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
<syntaxhighlight lang="mathematica"> |
|||
<lang Mathematica> |
|||
Print[Import["http://www.google.com/webhp?complete=1&hl=en", "Source"]] |
Print[Import["http://www.google.com/webhp?complete=1&hl=en", "Source"]] |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|MATLAB}} / {{header|Octave}}== |
=={{header|MATLAB}} / {{header|Octave}}== |
||
Line 1,879: | Line 1,879: | ||
In this example we initiate an HTTP request for a single random number from [http://www.random.org random.org]: |
In this example we initiate an HTTP request for a single random number from [http://www.random.org random.org]: |
||
<syntaxhighlight lang="matlab"> |
|||
<lang MATLAB> |
|||
>> random = urlread('http://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new') |
>> random = urlread('http://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new') |
||
Line 1,885: | Line 1,885: | ||
61 |
61 |
||
</syntaxhighlight> |
|||
</lang> |
|||
It is possible to make more complicated requests, specifically "GET" and "POST," which is explained in the [http://www.mathworks.com/help/matlab/ref/urlread.html documentation]. |
It is possible to make more complicated requests, specifically "GET" and "POST," which is explained in the [http://www.mathworks.com/help/matlab/ref/urlread.html documentation]. |
||
Line 1,893: | Line 1,893: | ||
=={{header|Nanoquery}}== |
=={{header|Nanoquery}}== |
||
< |
<syntaxhighlight lang="nanoquery">import http |
||
import url |
import url |
||
Line 1,901: | Line 1,901: | ||
response = client.get(url.getFile()) |
response = client.get(url.getFile()) |
||
println response.get("body")</ |
println response.get("body")</syntaxhighlight> |
||
=={{header|Nemerle}}== |
=={{header|Nemerle}}== |
||
< |
<syntaxhighlight lang="nemerle">using System; |
||
using System.Console; |
using System.Console; |
||
using System.Net; |
using System.Net; |
||
Line 1,920: | Line 1,920: | ||
myStream.Close() |
myStream.Close() |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|NetRexx}}== |
=={{header|NetRexx}}== |
||
Line 1,926: | Line 1,926: | ||
An implementation of the [[#Java|Java]] version shown above; demonstrating NetRexx's ability to exploit the rich Java SDK. |
An implementation of the [[#Java|Java]] version shown above; demonstrating NetRexx's ability to exploit the rich Java SDK. |
||
< |
<syntaxhighlight lang="netrexx">/* NetRexx */ |
||
options replace format comments java crossref symbols binary |
options replace format comments java crossref symbols binary |
||
Line 1,942: | Line 1,942: | ||
end |
end |
||
return</ |
return</syntaxhighlight> |
||
=={{header|NewLisp}}== |
=={{header|NewLisp}}== |
||
<syntaxhighlight lang="newlisp"> |
|||
<lang NewLisp> |
|||
(get-url "http://www.rosettacode.org") |
(get-url "http://www.rosettacode.org") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import httpclient |
||
var client = newHttpClient() |
var client = newHttpClient() |
||
echo client.getContent "http://rosettacode.org"</ |
echo client.getContent "http://rosettacode.org"</syntaxhighlight> |
||
=={{header|Objeck}}== |
=={{header|Objeck}}== |
||
< |
<syntaxhighlight lang="objeck">use HTTP; |
||
use Collection; |
use Collection; |
||
Line 1,966: | Line 1,966: | ||
}; |
}; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Objective-C}}== |
=={{header|Objective-C}}== |
||
< |
<syntaxhighlight lang="objc">#import <Foundation/Foundation.h> |
||
int main (int argc, const char * argv[]) { |
int main (int argc, const char * argv[]) { |
||
Line 1,985: | Line 1,985: | ||
} |
} |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
< |
<syntaxhighlight lang="ocaml"> |
||
let () = |
let () = |
||
let url = "http://www.rosettacode.org" in |
let url = "http://www.rosettacode.org" in |
||
Line 1,994: | Line 1,994: | ||
print_endline page_content; |
print_endline page_content; |
||
;; |
;; |
||
</syntaxhighlight> |
|||
</lang> |
|||
The source code of the function ''make_request'' is [[Web_Scraping/OCaml|here]]. |
The source code of the function ''make_request'' is [[Web_Scraping/OCaml|here]]. |
||
Line 2,001: | Line 2,001: | ||
{{libheader|libcurl}} |
{{libheader|libcurl}} |
||
< |
<syntaxhighlight lang="scheme"> |
||
(import (lib curl)) |
(import (lib curl)) |
||
Line 2,007: | Line 2,007: | ||
(curl 'url "http://rosettacode.org/") |
(curl 'url "http://rosettacode.org/") |
||
(curl 'perform) |
(curl 'perform) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|ooRexx}}== |
=={{header|ooRexx}}== |
||
Got this from a friend. Needs bsf4oorexx from sourceforge. |
Got this from a friend. Needs bsf4oorexx from sourceforge. |
||
<br>Note that rosettacode.org (as used by java and NetRexx) does not permit this access! |
<br>Note that rosettacode.org (as used by java and NetRexx) does not permit this access! |
||
< |
<syntaxhighlight lang="oorexx">url=.bsf~new("java.net.URL","http://teletext.orf.at") |
||
sc =.bsf~new("java.util.Scanner",url~openStream) |
sc =.bsf~new("java.util.Scanner",url~openStream) |
||
loop while sc~hasNext |
loop while sc~hasNext |
||
say sc~nextLine |
say sc~nextLine |
||
End |
End |
||
::requires BSF.CLS -- get Java camouflaging support</ |
::requires BSF.CLS -- get Java camouflaging support</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
massaged to avoid problems. |
massaged to avoid problems. |
||
Line 2,026: | Line 2,026: | ||
=={{header|Oz}}== |
=={{header|Oz}}== |
||
When creating a file object, it is possible to specify an URL instead of a filename: |
When creating a file object, it is possible to specify an URL instead of a filename: |
||
<syntaxhighlight lang="oz"> |
|||
<lang oz> |
|||
declare |
declare |
||
fun {GetPage Url} |
fun {GetPage Url} |
||
Line 2,037: | Line 2,037: | ||
in |
in |
||
{System.showInfo {GetPage "http://www.rosettacode.org"}} |
{System.showInfo {GetPage "http://www.rosettacode.org"}} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{libheader|OzHttpClient}} |
{{libheader|OzHttpClient}} |
||
If you need more fine-grained control of the request, you could use a custom library: |
If you need more fine-grained control of the request, you could use a custom library: |
||
<syntaxhighlight lang="oz"> |
|||
<lang oz> |
|||
declare |
declare |
||
[HTTPClient] = {Module.link ['x-ozlib://mesaros/net/HTTPClient.ozf']} |
[HTTPClient] = {Module.link ['x-ozlib://mesaros/net/HTTPClient.ozf']} |
||
Line 2,060: | Line 2,060: | ||
in |
in |
||
{System.showInfo {GetPage "http://www.rosettacode.org"}} |
{System.showInfo {GetPage "http://www.rosettacode.org"}} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
{{works with|Free Pascal}} |
{{works with|Free Pascal}} |
||
Using [http://wiki.freepascal.org/fphttpclient fphttpclient] |
Using [http://wiki.freepascal.org/fphttpclient fphttpclient] |
||
< |
<syntaxhighlight lang="pascal">{$mode objfpc}{$H+} |
||
uses fphttpclient; |
uses fphttpclient; |
||
Line 2,080: | Line 2,080: | ||
end; |
end; |
||
writeln(s) |
writeln(s) |
||
end.</ |
end.</syntaxhighlight> |
||
{{works with|Free Pascal}} {{libheader|CThreads}} {{libheader|Classes}} {{libheader|httpsend}} |
{{works with|Free Pascal}} {{libheader|CThreads}} {{libheader|Classes}} {{libheader|httpsend}} |
||
< |
<syntaxhighlight lang="pascal">program http; |
||
{$mode objfpc}{$H+} |
{$mode objfpc}{$H+} |
||
Line 2,130: | Line 2,130: | ||
Readln; |
Readln; |
||
end.</ |
end.</syntaxhighlight> |
||
=={{header|Peloton}}== |
=={{header|Peloton}}== |
||
English dialect, short form: |
English dialect, short form: |
||
< |
<syntaxhighlight lang="sgml"> |
||
<@ SAYURLLIT>http://rosettacode.org/wiki/Main_Page</@> |
<@ SAYURLLIT>http://rosettacode.org/wiki/Main_Page</@> |
||
</syntaxhighlight> |
|||
</lang> |
|||
English dialect, padded variable-length form: |
English dialect, padded variable-length form: |
||
< |
<syntaxhighlight lang="sgml"> |
||
<# SAY URLSOURCE LITERAL>http://rosettacode.org/wiki/Main_Page</#> |
<# SAY URLSOURCE LITERAL>http://rosettacode.org/wiki/Main_Page</#> |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
Line 2,152: | Line 2,152: | ||
This sample is nearly identical to the LWP sample except that it uses HTTP::Tiny which was added to the core libraries in [[Perl/5.14]]. |
This sample is nearly identical to the LWP sample except that it uses HTTP::Tiny which was added to the core libraries in [[Perl/5.14]]. |
||
< |
<syntaxhighlight lang="perl">use strict; use warnings; |
||
require 5.014; # check HTTP::Tiny part of core |
require 5.014; # check HTTP::Tiny part of core |
||
use HTTP::Tiny; |
use HTTP::Tiny; |
||
print( HTTP::Tiny->new()->get( 'http://rosettacode.org')->{content} );</ |
print( HTTP::Tiny->new()->get( 'http://rosettacode.org')->{content} );</syntaxhighlight> |
||
===Library examples=== |
===Library examples=== |
||
Line 2,165: | Line 2,165: | ||
Classic LWP sample. |
Classic LWP sample. |
||
< |
<syntaxhighlight lang="perl">use LWP::Simple qw/get $ua/; |
||
$ua->agent(undef) ; # cloudflare blocks default LWP agent |
$ua->agent(undef) ; # cloudflare blocks default LWP agent |
||
print( get("http://www.rosettacode.org") );</ |
print( get("http://www.rosettacode.org") );</syntaxhighlight> |
||
or with more error-checking |
or with more error-checking |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use LWP::UserAgent; |
use LWP::UserAgent; |
||
Line 2,179: | Line 2,179: | ||
$response->is_success or die "Failed to GET '$url': ", $response->status_line; |
$response->is_success or die "Failed to GET '$url': ", $response->status_line; |
||
print $response->as_string</ |
print $response->as_string</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{libheader|Phix/libcurl}} |
{{libheader|Phix/libcurl}} |
||
Note that curl_easy_get_file() is better suited to multi-megabyte downloads than curl_easy_perform_ex(). |
Note that curl_easy_get_file() is better suited to multi-megabyte downloads than curl_easy_perform_ex(). |
||
<!--< |
<!--<syntaxhighlight lang="phix">(notonline)--> |
||
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins<span style="color: #0000FF;">\<span style="color: #000000;">libcurl<span style="color: #0000FF;">.<span style="color: #000000;">e</span> |
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins<span style="color: #0000FF;">\<span style="color: #000000;">libcurl<span style="color: #0000FF;">.<span style="color: #000000;">e</span> |
||
<span style="color: #7060A8;">curl_global_init<span style="color: #0000FF;">(<span style="color: #0000FF;">)</span> |
<span style="color: #7060A8;">curl_global_init<span style="color: #0000FF;">(<span style="color: #0000FF;">)</span> |
||
Line 2,194: | Line 2,194: | ||
<span style="color: #7060A8;">puts<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #000000;">res<span style="color: #0000FF;">) |
<span style="color: #7060A8;">puts<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #000000;">res<span style="color: #0000FF;">) |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,208: | Line 2,208: | ||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
< |
<syntaxhighlight lang="php"> |
||
readfile("http://www.rosettacode.org"); |
readfile("http://www.rosettacode.org"); |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
<syntaxhighlight lang="picolisp"> |
|||
<lang PicoLisp> |
|||
(load "@lib/http.l") |
(load "@lib/http.l") |
||
(client "rosettacode.org" 80 NIL # Connect to rosettacode |
(client "rosettacode.org" 80 NIL # Connect to rosettacode |
||
(out NIL (echo)) ) # Echo to standard output |
(out NIL (echo)) ) # Echo to standard output |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Pike}}== |
=={{header|Pike}}== |
||
< |
<syntaxhighlight lang="pike"> |
||
write("%s",Protocols.HTTP.get_url_data("http://www.rosettacode.org")); |
write("%s",Protocols.HTTP.get_url_data("http://www.rosettacode.org")); |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
< |
<syntaxhighlight lang="powershell"> |
||
$wc = New-Object Net.WebClient |
$wc = New-Object Net.WebClient |
||
$wc.DownloadString('http://www.rosettacode.org') |
$wc.DownloadString('http://www.rosettacode.org') |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Prolog}}== |
=={{header|Prolog}}== |
||
Works with SWI-Prolog and library http/http_open. (Extract from the doc). |
Works with SWI-Prolog and library http/http_open. (Extract from the doc). |
||
<syntaxhighlight lang="prolog"> |
|||
<lang Prolog> |
|||
:- use_module(library( http/http_open )). |
:- use_module(library( http/http_open )). |
||
Line 2,241: | Line 2,241: | ||
copy_stream_data(In, user_output), |
copy_stream_data(In, user_output), |
||
close(In). |
close(In). |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
<syntaxhighlight lang="purebasic"> |
|||
<lang PureBasic> |
|||
InitNetwork() |
InitNetwork() |
||
OpenConsole() |
OpenConsole() |
||
Line 2,262: | Line 2,262: | ||
DeleteFile(filename$) |
DeleteFile(filename$) |
||
EndIf |
EndIf |
||
</syntaxhighlight> |
|||
</lang> |
|||
Another solution using general networking commands |
Another solution using general networking commands |
||
<syntaxhighlight lang="purebasic"> |
|||
<lang PureBasic> |
|||
InitNetwork() |
InitNetwork() |
||
OpenConsole() |
OpenConsole() |
||
Line 2,280: | Line 2,280: | ||
; next line only to prevent console from closing on Windows |
; next line only to prevent console from closing on Windows |
||
Input() |
Input() |
||
</syntaxhighlight> |
|||
</lang> |
|||
Of course you could use wget too. |
Of course you could use wget too. |
||
Line 2,288: | Line 2,288: | ||
;Python 3: |
;Python 3: |
||
Using the [http://docs.python.org/py3k/library/urllib.request.html urllib.request] module. |
Using the [http://docs.python.org/py3k/library/urllib.request.html urllib.request] module. |
||
< |
<syntaxhighlight lang="python"> |
||
import urllib.request |
import urllib.request |
||
print(urllib.request.urlopen("http://rosettacode.org").read()) |
print(urllib.request.urlopen("http://rosettacode.org").read()) |
||
</syntaxhighlight> |
|||
</lang> |
|||
Using a more low-level [https://docs.python.org/3/library/http.client.html http.client] library. |
Using a more low-level [https://docs.python.org/3/library/http.client.html http.client] library. |
||
< |
<syntaxhighlight lang="python"> |
||
from http.client import HTTPConnection |
from http.client import HTTPConnection |
||
conn = HTTPConnection("example.com") |
conn = HTTPConnection("example.com") |
||
Line 2,302: | Line 2,302: | ||
result = conn.getresponse() |
result = conn.getresponse() |
||
r1 = result.read() # This retrieves the entire contents. |
r1 = result.read() # This retrieves the entire contents. |
||
</syntaxhighlight> |
|||
</lang> |
|||
;Python 2: |
;Python 2: |
||
Using the [http://docs.python.org/library/urllib.html urllib] library. |
Using the [http://docs.python.org/library/urllib.html urllib] library. |
||
< |
<syntaxhighlight lang="python"> |
||
import urllib |
import urllib |
||
print urllib.urlopen("http://rosettacode.org").read() |
print urllib.urlopen("http://rosettacode.org").read() |
||
</syntaxhighlight> |
|||
</lang> |
|||
Using the [http://docs.python.org/library/urllib2.html urllib2] library. |
Using the [http://docs.python.org/library/urllib2.html urllib2] library. |
||
< |
<syntaxhighlight lang="python"> |
||
import urllib2 |
import urllib2 |
||
print urllib2.urlopen("http://rosettacode.org").read() |
print urllib2.urlopen("http://rosettacode.org").read() |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{libheader|Requests}} |
{{libheader|Requests}} |
||
{{works with|Python|2.7, 3.4–3.7}} |
{{works with|Python|2.7, 3.4–3.7}} |
||
<syntaxhighlight lang="python"> |
|||
<lang Python> |
|||
import requests |
import requests |
||
print(requests.get("http://rosettacode.org").text) |
print(requests.get("http://rosettacode.org").text) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|R}}== |
=={{header|R}}== |
||
Line 2,331: | Line 2,331: | ||
First, retrieve the webpage. |
First, retrieve the webpage. |
||
<syntaxhighlight lang="r"> |
|||
<lang R> |
|||
library(RCurl) |
library(RCurl) |
||
webpage <- getURL("http://rosettacode.org") |
webpage <- getURL("http://rosettacode.org") |
||
Line 2,342: | Line 2,342: | ||
.opts=list(proxy="123.123.123.123", proxyusername="domain\\username", proxypassword="mypassword", proxyport=8080)) |
.opts=list(proxy="123.123.123.123", proxyusername="domain\\username", proxypassword="mypassword", proxyport=8080)) |
||
#Don't forget that backslashes in your username or password need to be escaped! |
#Don't forget that backslashes in your username or password need to be escaped! |
||
</syntaxhighlight> |
|||
</lang> |
|||
Now parse the html code into a tree and print the html. |
Now parse the html code into a tree and print the html. |
||
<syntaxhighlight lang="r"> |
|||
<lang R> |
|||
library(XML) |
library(XML) |
||
pagetree <- htmlTreeParse(webpage ) |
pagetree <- htmlTreeParse(webpage ) |
||
pagetree$children$html |
pagetree$children$html |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
<syntaxhighlight lang="racket"> |
|||
<lang Racket> |
|||
#lang racket |
#lang racket |
||
(require net/url) |
(require net/url) |
||
Line 2,359: | Line 2,359: | ||
#:redirections 100) |
#:redirections 100) |
||
(current-output-port)) |
(current-output-port)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
Line 2,366: | Line 2,366: | ||
Using LWP::Simple from [https://modules.raku.org/search/?q=LWP%3A%3ASimple the Raku ecosystem]. |
Using LWP::Simple from [https://modules.raku.org/search/?q=LWP%3A%3ASimple the Raku ecosystem]. |
||
<lang |
<syntaxhighlight lang="raku" line>use LWP::Simple; |
||
print LWP::Simple.get("http://www.rosettacode.org"); |
print LWP::Simple.get("http://www.rosettacode.org"); |
||
</syntaxhighlight> |
|||
</lang> |
|||
or, without LWP::Simple: |
or, without LWP::Simple: |
||
<lang |
<syntaxhighlight lang="raku" line>my $socket = IO::Socket::INET.new(host => "www.rosettacode.org", |
||
port => 80,); |
port => 80,); |
||
$socket.print("GET / HTTP/1.0\r\n\r\n"); |
$socket.print("GET / HTTP/1.0\r\n\r\n"); |
||
print $socket.recv(); |
print $socket.recv(); |
||
$socket.close; |
$socket.close; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|REALbasic}}== |
=={{header|REALbasic}}== |
||
REALBasic provides an HTTPSocket class for handling HTTP connections. The 'Get' method of the HTTPSocket is overloaded and can download data to a file or return data as a string, in both cases a timeout argument can be passed. |
REALBasic provides an HTTPSocket class for handling HTTP connections. The 'Get' method of the HTTPSocket is overloaded and can download data to a file or return data as a string, in both cases a timeout argument can be passed. |
||
<syntaxhighlight lang="realbasic"> |
|||
<lang REALbasic> |
|||
Dim sock As New HTTPSocket |
Dim sock As New HTTPSocket |
||
Print(sock.Get("http://www.rosettacode.org", 10)) //set the timeout period to 10 seconds. |
Print(sock.Get("http://www.rosettacode.org", 10)) //set the timeout period to 10 seconds. |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|REBOL}}== |
=={{header|REBOL}}== |
||
<syntaxhighlight lang="rebol"> |
|||
<lang REBOL> |
|||
print read http://rosettacode.org |
print read http://rosettacode.org |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Line 2,396: | Line 2,396: | ||
This script takes an URL as an argument and displays the content on the terminal. It uses the external program `curl` to perform both the acquisition of the data and the display. |
This script takes an URL as an argument and displays the content on the terminal. It uses the external program `curl` to perform both the acquisition of the data and the display. |
||
< |
<syntaxhighlight lang="rexx">/* ft=rexx */ |
||
/* GET2.RX - Display contents of an URL on the terminal. */ |
/* GET2.RX - Display contents of an URL on the terminal. */ |
||
/* Usage: rexx get.rx http://rosettacode.org */ |
/* Usage: rexx get.rx http://rosettacode.org */ |
||
parse arg url . |
parse arg url . |
||
'curl' url</ |
'curl' url</syntaxhighlight> |
||
A simple change to the script will redirect the output to an internal variable for internal processing. (Our "internal processing" in this case is to display it.) |
A simple change to the script will redirect the output to an internal variable for internal processing. (Our "internal processing" in this case is to display it.) |
||
< |
<syntaxhighlight lang="rexx">/* ft=rexx */ |
||
/* GET2.RX - Display contents of an URL on the terminal. */ |
/* GET2.RX - Display contents of an URL on the terminal. */ |
||
/* Usage: rexx get2.rx http://rosettacode.org */ |
/* Usage: rexx get2.rx http://rosettacode.org */ |
||
Line 2,411: | Line 2,411: | ||
do i = 1 to stuff.0 |
do i = 1 to stuff.0 |
||
say stuff.i |
say stuff.i |
||
end</ |
end</syntaxhighlight> |
||
Another simple change redirects the output to another external program like a shell pipe. |
Another simple change redirects the output to another external program like a shell pipe. |
||
< |
<syntaxhighlight lang="rexx">/* ft=rexx */ |
||
/* GET3.RX - Display contents of an URL on the terminal. */ |
/* GET3.RX - Display contents of an URL on the terminal. */ |
||
/* Usage: rexx get3.rx http://rosettacode.org */ |
/* Usage: rexx get3.rx http://rosettacode.org */ |
||
parse arg url . |
parse arg url . |
||
address system 'curl' url with output fifo '' |
address system 'curl' url with output fifo '' |
||
address system 'more' with input fifo ''</ |
address system 'more' with input fifo ''</syntaxhighlight> |
||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
See download("http://rosettacode.org") |
See download("http://rosettacode.org") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|RLaB}}== |
=={{header|RLaB}}== |
||
Line 2,452: | Line 2,452: | ||
Yahoo [http://ichart.finance.yahoo.com/table.csv?s=PFE&a=00&b=4&c=1982&d=00&e=10&f=2010&g=d&ignore=.csv]. |
Yahoo [http://ichart.finance.yahoo.com/table.csv?s=PFE&a=00&b=4&c=1982&d=00&e=10&f=2010&g=d&ignore=.csv]. |
||
<syntaxhighlight lang="rlab"> |
|||
<lang RLaB> |
|||
// get cvs data from Yahoo for Pfeizer (PFE) |
// get cvs data from Yahoo for Pfeizer (PFE) |
||
url="http://ichart.finance.yahoo.com/table.csv?s=PFE&a=00&b=4&c=1982&d=00&e=10&f=2010&g=d&ignore=.csv"; |
url="http://ichart.finance.yahoo.com/table.csv?s=PFE&a=00&b=4&c=1982&d=00&e=10&f=2010&g=d&ignore=.csv"; |
||
Line 2,463: | Line 2,463: | ||
x = readm(url); |
x = readm(url); |
||
close (url); |
close (url); |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
The simple way loads the entire content into memory, then prints it. |
The simple way loads the entire content into memory, then prints it. |
||
< |
<syntaxhighlight lang="ruby"> |
||
require 'open-uri' |
require 'open-uri' |
||
print open("http://rosettacode.org") {|f| f.read} |
print open("http://rosettacode.org") {|f| f.read} |
||
</syntaxhighlight> |
|||
</lang> |
|||
If the content might be large, the better way uses FileUtils.copy_stream. |
If the content might be large, the better way uses FileUtils.copy_stream. |
||
< |
<syntaxhighlight lang="ruby"> |
||
require 'fileutils' |
require 'fileutils' |
||
require 'open-uri' |
require 'open-uri' |
||
open("http://rosettacode.org/") {|f| FileUtils.copy_stream(f, $stdout)} |
open("http://rosettacode.org/") {|f| FileUtils.copy_stream(f, $stdout)} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |
||
< |
<syntaxhighlight lang="runbasic">print httpget$("http://rosettacode.org/wiki/Main_Page")</syntaxhighlight> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
Cargo.toml |
Cargo.toml |
||
< |
<syntaxhighlight lang="toml"> |
||
[dependencies] |
[dependencies] |
||
hyper = "0.6" |
hyper = "0.6" |
||
</syntaxhighlight> |
|||
</lang> |
|||
src/main.rs |
src/main.rs |
||
< |
<syntaxhighlight lang="rust"> |
||
//cargo-deps: hyper="0.6" |
//cargo-deps: hyper="0.6" |
||
// The above line can be used with cargo-script which makes cargo's dependency handling more convenient for small programs |
// The above line can be used with cargo-script which makes cargo's dependency handling more convenient for small programs |
||
Line 2,508: | Line 2,508: | ||
println!("{}", body); |
println!("{}", body); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
{{libheader|Scala}} |
{{libheader|Scala}} |
||
< |
<syntaxhighlight lang="scala">import scala.io.Source |
||
object HttpTest extends App { |
object HttpTest extends App { |
||
Line 2,518: | Line 2,518: | ||
Source.fromURL("http://www.rosettacode.org").getLines.foreach(println) |
Source.fromURL("http://www.rosettacode.org").getLines.foreach(println) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
{{works with|Guile}} |
{{works with|Guile}} |
||
< |
<syntaxhighlight lang="scheme"> |
||
; Use the regular expression module to parse the url (included with Guile) |
; Use the regular expression module to parse the url (included with Guile) |
||
(use-modules (ice-9 regex)) |
(use-modules (ice-9 regex)) |
||
Line 2,550: | Line 2,550: | ||
(do ((c (read-char s) (read-char s))) ((eof-object? c)) |
(do ((c (read-char s) (read-char s))) ((eof-object? c)) |
||
(display c))) |
(display c))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{works with|Chicken Scheme}} |
{{works with|Chicken Scheme}} |
||
Using the [http://api.call-cc.org/doc/http-client http-client] library, this is trivial. |
Using the [http://api.call-cc.org/doc/http-client http-client] library, this is trivial. |
||
< |
<syntaxhighlight lang="scheme"> |
||
(use http-client) |
(use http-client) |
||
(print |
(print |
||
(with-input-from-request "http://google.com/" |
(with-input-from-request "http://google.com/" |
||
#f read-string)) |
#f read-string)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
Line 2,565: | Line 2,565: | ||
which gets data specified by an URL using the HTTP protocol. |
which gets data specified by an URL using the HTTP protocol. |
||
< |
<syntaxhighlight lang="seed7"> |
||
$ include "seed7_05.s7i"; |
$ include "seed7_05.s7i"; |
||
include "gethttp.s7i"; |
include "gethttp.s7i"; |
||
Line 2,572: | Line 2,572: | ||
begin |
begin |
||
writeln(getHttp("www.rosettacode.org")); |
writeln(getHttp("www.rosettacode.org")); |
||
end func;</ |
end func;</syntaxhighlight> |
||
=={{header|SenseTalk}}== |
=={{header|SenseTalk}}== |
||
< |
<syntaxhighlight lang="sensetalk">put url "http://www.rosettacode.org"</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
Sidef can load and use Perl modules: |
Sidef can load and use Perl modules: |
||
< |
<syntaxhighlight lang="ruby">func get(url) { |
||
var lwp = ( |
var lwp = ( |
||
try { require('LWP::UserAgent') } |
try { require('LWP::UserAgent') } |
||
Line 2,591: | Line 2,591: | ||
} |
} |
||
print get("http://rosettacode.org")</ |
print get("http://rosettacode.org")</syntaxhighlight> |
||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
{{works with|Pharo}} |
{{works with|Pharo}} |
||
< |
<syntaxhighlight lang="smalltalk"> |
||
Transcript show: 'http://rosettacode.org' asUrl retrieveContents contentStream. |
Transcript show: 'http://rosettacode.org' asUrl retrieveContents contentStream. |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|SNOBOL4}}== |
=={{header|SNOBOL4}}== |
||
{{works with|Macro SNOBOL4 in C}} |
{{works with|Macro SNOBOL4 in C}} |
||
< |
<syntaxhighlight lang="snobol">-include "tcp.sno" |
||
tcp.open(.conn,'www.rosettacode.org','http') :s(cont1) |
tcp.open(.conn,'www.rosettacode.org','http') :s(cont1) |
||
terminal = "cannot open" :(end) |
terminal = "cannot open" :(end) |
||
Line 2,608: | Line 2,608: | ||
tcp.close(.conn) |
tcp.close(.conn) |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
< |
<syntaxhighlight lang="swift">import Foundation |
||
let request = NSURLRequest(URL: NSURL(string: "http://rosettacode.org/")!) |
let request = NSURLRequest(URL: NSURL(string: "http://rosettacode.org/")!) |
||
Line 2,625: | Line 2,625: | ||
} |
} |
||
CFRunLoopRun() // dispatch</ |
CFRunLoopRun() // dispatch</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
Note that the <code>http</code> package is distributed as part of Tcl. |
Note that the <code>http</code> package is distributed as part of Tcl. |
||
< |
<syntaxhighlight lang="tcl"> |
||
package require http |
package require http |
||
set request [http::geturl "http://www.rosettacode.org"] |
set request [http::geturl "http://www.rosettacode.org"] |
||
puts [http::data $request] |
puts [http::data $request] |
||
http::cleanup $request</ |
http::cleanup $request</syntaxhighlight> |
||
=={{header|TSE SAL}}== |
=={{header|TSE SAL}}== |
||
<syntaxhighlight lang="tse sal"> |
|||
<lang TSE SAL> |
|||
DLL "<urlmon.dll>" |
DLL "<urlmon.dll>" |
||
Line 2,663: | Line 2,663: | ||
END |
END |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|TUSCRIPT}}== |
=={{header|TUSCRIPT}}== |
||
< |
<syntaxhighlight lang="tuscript"> |
||
$$ MODE TUSCRIPT |
$$ MODE TUSCRIPT |
||
SET DATEN = REQUEST ("http://www.rosettacode.org") |
SET DATEN = REQUEST ("http://www.rosettacode.org") |
||
*{daten} |
*{daten} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
< |
<syntaxhighlight lang="bash">curl -s -L http://rosettacode.org/</syntaxhighlight> |
||
< |
<syntaxhighlight lang="bash">lynx -source http://rosettacode.org/</syntaxhighlight> |
||
< |
<syntaxhighlight lang="bash">wget -O - -q http://rosettacode.org/</syntaxhighlight> |
||
< |
<syntaxhighlight lang="bash">lftp -c "cat http://rosettacode.org/"</syntaxhighlight> |
||
{{works with|BSD}} |
{{works with|BSD}} |
||
< |
<syntaxhighlight lang="bash">ftp -o - http://rosettacode.org 2>/dev/null</syntaxhighlight> |
||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
Line 2,688: | Line 2,688: | ||
Based on code at [http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/how-to-retrieve-html-web-pages-with-vbscript-via-the-microsoftxmlhttp-object/ How to retrieve HTML web pages with VBScript via the Microsoft.XmlHttp object] |
Based on code at [http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/how-to-retrieve-html-web-pages-with-vbscript-via-the-microsoftxmlhttp-object/ How to retrieve HTML web pages with VBScript via the Microsoft.XmlHttp object] |
||
<syntaxhighlight lang="vb"> |
|||
<lang vb> |
|||
Option Explicit |
Option Explicit |
||
Line 2,706: | Line 2,706: | ||
Set oHTTP = Nothing |
Set oHTTP = Nothing |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Visual Basic}}== |
=={{header|Visual Basic}}== |
||
Line 2,715: | Line 2,715: | ||
{{works with|VBA|6.5}} |
{{works with|VBA|6.5}} |
||
{{works with|VBA|7.1}} |
{{works with|VBA|7.1}} |
||
< |
<syntaxhighlight lang="vb">Sub Main() |
||
Dim HttpReq As WinHttp.WinHttpRequest |
Dim HttpReq As WinHttp.WinHttpRequest |
||
' in the "references" dialog of the IDE, check |
' in the "references" dialog of the IDE, check |
||
Line 2,729: | Line 2,729: | ||
HttpReq.Send |
HttpReq.Send |
||
Debug.Print HttpReq.ResponseText |
Debug.Print HttpReq.ResponseText |
||
End Sub</ |
End Sub</syntaxhighlight> |
||
=={{header|Visual Basic .NET}}== |
=={{header|Visual Basic .NET}}== |
||
< |
<syntaxhighlight lang="vbnet"> |
||
Imports System.Net |
Imports System.Net |
||
Line 2,738: | Line 2,738: | ||
Dim content As String = client.DownloadString("http://www.google.com") |
Dim content As String = client.DownloadString("http://www.google.com") |
||
Console.WriteLine(content) |
Console.WriteLine(content) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
Line 2,744: | Line 2,744: | ||
{{libheader|libcurl}} |
{{libheader|libcurl}} |
||
An embedded program so we can ask the C host to communicate with libcurl for us. |
An embedded program so we can ask the C host to communicate with libcurl for us. |
||
< |
<syntaxhighlight lang="ecmascript">/* http.wren */ |
||
var CURLOPT_URL = 10002 |
var CURLOPT_URL = 10002 |
||
Line 2,774: | Line 2,774: | ||
return |
return |
||
} |
} |
||
curl.easyCleanup()</ |
curl.easyCleanup()</syntaxhighlight> |
||
<br> |
<br> |
||
We now embed this in the following C program, compile and run it. |
We now embed this in the following C program, compile and run it. |
||
< |
<syntaxhighlight lang="c">/* gcc http.c -o http -lcurl -lwren -lm */ |
||
#include <stdio.h> |
#include <stdio.h> |
||
Line 2,903: | Line 2,903: | ||
free(script); |
free(script); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|X86-64 Assembly}}== |
=={{header|X86-64 Assembly}}== |
||
===UASM 5.52=== |
===UASM 5.52=== |
||
The same as the [[Sockets]] example, Just with a read method added... |
The same as the [[Sockets]] example, Just with a read method added... |
||
< |
<syntaxhighlight lang="asm"> |
||
option casemap:none |
option casemap:none |
||
option literals:on |
option literals:on |
||
Line 3,110: | Line 3,110: | ||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
File htmlGet.zkl. This uses HTTP/1.0 Protocol to avoid chunked data. Or use cURL (see https example). |
File htmlGet.zkl. This uses HTTP/1.0 Protocol to avoid chunked data. Or use cURL (see https example). |
||
< |
<syntaxhighlight lang="zkl">url := ask(0,"URL: "); |
||
host := url; |
host := url; |
||
Line 3,127: | Line 3,127: | ||
server.write(get); |
server.write(get); |
||
data := server.read(True); |
data := server.read(True); |
||
println(data.text);</ |
println(data.text);</syntaxhighlight> |
||
zkl htmlGet.zkl rosettacode.org/wiki/HTTP |
zkl htmlGet.zkl rosettacode.org/wiki/HTTP |
||
{{out}} |
{{out}} |
||
Line 3,163: | Line 3,163: | ||
=={{header|Zoea}}== |
=={{header|Zoea}}== |
||
<syntaxhighlight lang="zoea"> |
|||
<lang Zoea> |
|||
program: http |
program: http |
||
input: 'https://zoea.co.uk/examples/test.txt' |
input: 'https://zoea.co.uk/examples/test.txt' |
||
output: 'hello from zoea' |
output: 'hello from zoea' |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Zoea Visual}}== |
=={{header|Zoea Visual}}== |
||
Line 3,173: | Line 3,173: | ||
=={{header|Zsh}}== |
=={{header|Zsh}}== |
||
< |
<syntaxhighlight lang="zsh"> |
||
zmodload zsh/net/tcp |
zmodload zsh/net/tcp |
||
ztcp example.com 80 |
ztcp example.com 80 |
||
Line 3,180: | Line 3,180: | ||
while read -u $fd -r -e -t 1; do; :; done |
while read -u $fd -r -e -t 1; do; :; done |
||
ztcp -c $fd |
ztcp -c $fd |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{omit from|Applesoft BASIC|No TCP/IP network support on Apple II}} |
{{omit from|Applesoft BASIC|No TCP/IP network support on Apple II}} |