HTTP: Difference between revisions

18,196 bytes added ,  5 months ago
m
m (→‎{{header|Phix}}: added syntax colouring the hard way)
m (→‎{{header|Wren}}: Minor tidy)
 
(27 intermediate revisions by 17 users not shown)
Line 1:
{{task|Programming environment operations}}
[[Category:Networking and Web Interaction]]
 
;Task:
Access and print a [[wp:Uniform Resource Locator|URL]]'s content (the located resource) to the console.
 
There is a separate task for [[HTTPS Request]]s.
<br><br>
 
=={{header|8th}}==
<langsyntaxhighlight lang="forth">
"http://www.rosettacode.org" net:get drop >s .
</syntaxhighlight>
</lang>
 
=={{header|ABAP}}==
This works for ABAP Version 7.40 and above
<syntaxhighlight lang="abap">
<lang ABAP>
report z_http.
 
Line 49 ⟶ 51:
write / <output_line>.
endloop.
</syntaxhighlight>
</lang>
 
{{out}}
Line 65 ⟶ 67:
 
=={{header|ActionScript}}==
<langsyntaxhighlight lang="actionscript">
package
{
Line 87 ⟶ 89:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Ada}}==
{{libheader|AWS}}
<langsyntaxhighlight lang="ada">
with Ada.Text_IO; use Ada.Text_IO;
 
Line 101 ⟶ 103:
Put_Line (AWS.Response.Message_Body (AWS.Client.Get (URL => "http://www.rosettacode.org")));
end HTTP_Request;
</syntaxhighlight>
</lang>
 
=={{header|ALGOL 68}}==
Line 109 ⟶ 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''}}
 
<langsyntaxhighlight lang="algol68">
STRING domain="rosettacode.org";
STRING page="wiki/Main_Page";
Line 139 ⟶ 141:
ELSE print (strerror (rc))
FI
</syntaxhighlight>
</lang>
=={{header|Amazing Hopper}}==
<syntaxhighlight lang="amazing hopper">
#include <hopper.h>
main:
s=`curl -s -L https://rosettacode.org/wiki/HTTP`
{s}len, lenght=0, mov(lenght)
{"Size = ",lenght,"\nContent = \n",s}println
exit(0)
</syntaxhighlight>
{{out}}
<pre>
Size = 402474
Content =
<!DOCTYPE html>
<html lang="en" dir="ltr" class="client-nojs">
<head>
<meta charset="UTF-8" />
...
</pre>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">print read "http://rosettacode.org"</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">
<lang AutoHotkey>
UrlDownloadToFile, http://rosettacode.org, url.html
Run, cmd /k type url.html
</syntaxhighlight>
</lang>
 
=={{header|AWK}}==
{{works with|gawk}}
<langsyntaxhighlight lang="awk">BEGIN {
site="en.wikipedia.org"
path="/wiki/"
Line 172 ⟶ 193:
 
print ship
}</langsyntaxhighlight>
 
=={{header|BaCon}}==
<langsyntaxhighlight lang="qbasic">'
' Read and display a website
'
Line 192 ⟶ 213:
CLOSE NETWORK mynet
PRINT total$
</syntaxhighlight>
</lang>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="batch">
curl.exe -s -L http://rosettacode.org/
</syntaxhighlight>
</lang>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> SYS "LoadLibrary", "URLMON.DLL" TO urlmon%
SYS "GetProcAddress", urlmon%, "URLDownloadToFileA" TO URLDownloadToFile
Line 209 ⟶ 230:
IF fail% ERROR 100, "File download failed"
OSCLI "TYPE """ + file$ + """"</langsyntaxhighlight>
 
=={{header|Biferno}}==
simple one-liner using httpExt and quick print $
<langsyntaxhighlight Bifernolang="biferno">$httpExt.ExecRemote("www.tabasoft.it")</langsyntaxhighlight>
 
=={{header|C}}==
{{libheader|libcurl}}
 
<syntaxhighlight lang="c">
<lang c>
#include <stdio.h>
#include <stdlib.h>
Line 241 ⟶ 262:
return EXIT_SUCCESS;
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp}}==
<langsyntaxhighlight lang="csharp">
using System;
using System.Text;
Line 258 ⟶ 279:
}
}
</syntaxhighlight>
</lang>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">
#include <winsock2.h>
#include <ws2tcpip.h>
Line 300 ⟶ 321:
return 0;
}
</syntaxhighlight>
</lang>
 
{{libheader|U++}}
 
<langsyntaxhighlight lang="cpp">
#include <Web/Web.h>
 
Line 313 ⟶ 334:
Cout() << HttpClient("www.rosettacode.org").ExecuteRedirect();
}
</syntaxhighlight>
</lang>
 
=={{header|Caché ObjectScript}}==
Line 326 ⟶ 347:
=={{header|Clojure}}==
Using the Java API:
<langsyntaxhighlight lang="clojure">
(defn get-http [url]
(let [sc (java.util.Scanner.
Line 333 ⟶ 354:
(println (.nextLine sc)))))
(get-http "http://www.rosettacode.org")
</syntaxhighlight>
</lang>
 
Using <code>clojure.contrib.http.agent</code>:
<langsyntaxhighlight lang="clojure">
(ns example
(:use [clojure.contrib.http.agent :only (string http-agent)]))
 
(println (string (http-agent "http://www.rosettacode.org/")))
</syntaxhighlight>
</lang>
 
{{works with|Clojure|1.2}}
<langsyntaxhighlight lang="clojure">
(print (slurp "http://www.rosettacode.org/"))
</syntaxhighlight>
</lang>
 
=={{header|COBOL}}==
Line 352 ⟶ 373:
Tested with GnuCOBOL
 
<langsyntaxhighlight lang="cobol">COBOL >>SOURCE FORMAT IS FIXED
identification division.
program-id. curl-rosetta.
Line 643 ⟶ 664:
 
goback.
end program curl-write-callback.</langsyntaxhighlight>
 
and a copybook
 
<langsyntaxhighlight lang="cobol"> *> manifest constants for libcurl
*> Usage: COPY occurlsym inside data division
*> Taken from include/curl/curl.h 2013-12-19
Line 838 ⟶ 859:
03 FILLER PIC X(30) VALUE "CURLE_AGAIN ".
01 FILLER REDEFINES LIBCURL_ERRORS.
02 CURLEMSG OCCURS 81 TIMES PIC X(30).</langsyntaxhighlight>
 
{{out}}
Line 853 ⟶ 874:
 
=={{header|ColdFusion}}==
<langsyntaxhighlight lang="coldfusion">
<cfhttp url="http://www.rosettacode.org" result="result">
<cfoutput>#result.FileContent#</cfoutput>
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
CLISP provides an extension function to read http sources. Other implementations may do this differently.
{{works with|CLISP}}
<langsyntaxhighlight lang="lisp">
(defun wget-clisp (url)
(ext:with-http-input (stream url)
Line 867 ⟶ 888:
while line
do (format t "~a~%" line))))
</syntaxhighlight>
</lang>
 
{{libheader|DRAKMA}}
Line 873 ⟶ 894:
First grabbing the entire body as a string, and then by pulling from a stream (as in the CLISP example).
 
<langsyntaxhighlight lang="lisp">
(defun wget-drakma-string (url &optional (out *standard-output*))
"Grab the body as a string, and write it to out."
Line 884 ⟶ 905:
while line do (write-line line out)
finally (close body)))
</syntaxhighlight>
</lang>
 
{{libheader|Dexador}}
 
<syntaxhighlight lang="lisp">
(format t "~a~%" (nth-value 0 (dex:get "http://www.w3.org/")))
</syntaxhighlight>
 
=={{header|Crystal}}==
<langsyntaxhighlight lang="crystal">
require "http/client"
 
HTTP::Client.get("http://google.com")
</syntaxhighlight>
</lang>
 
=={{header|D}}==
{{libheader|phobos}}
<syntaxhighlight lang="d">
<lang D>
void main() {
import std.stdio, std.net.curl;
writeln(get("http://google.com"));
}
</syntaxhighlight>
</lang>
 
{{libheader|tango}}
 
<syntaxhighlight lang="d">
<lang D>
import tango.io.Console;
import tango.net.http.HttpGet;
Line 911 ⟶ 938:
Cout.stream.copy( (new HttpGet("http://google.com")).open );
}
</syntaxhighlight>
</lang>
 
Or more operating directly on the socket:
 
<syntaxhighlight lang="d">
<lang D>
import tango.io.Console;
import tango.net.InternetAddress;
Line 926 ⟶ 953:
Cout.stream.copy (site);
}
</syntaxhighlight>
</lang>
 
=={{header|Dart}}==
Using the stand-alone VM:
<langsyntaxhighlight lang="d">import 'dart:io';
void main(){
var url = 'http://rosettacode.org';
Line 937 ⟶ 964:
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) => response.pipe(stdout));
}</langsyntaxhighlight>
 
=={{header|Delphi}}==
Simple example using the free Synapse TCP/IP library [http://www.ararat.cz/synapse/doku.php/download]
 
<syntaxhighlight lang="delphi">
<lang Delphi>
program HTTP;
 
Line 986 ⟶ 1,013:
 
end.
</syntaxhighlight>
</lang>
 
 
Using Indy:
 
<syntaxhighlight lang="delphi">
<lang Delphi>
program ShowHTTP;
 
Line 1,011 ⟶ 1,038:
end;
end.
</syntaxhighlight>
</lang>
 
=={{header|Dragon}}==
<langsyntaxhighlight lang="dragon">select "http"
select "std"
 
http("http://www.rosettacode.org", ::echo)
</syntaxhighlight>
</lang>
 
=={{header|E}}==
 
<syntaxhighlight lang="e">
<lang e>
when (def t := <http://www.rosettacode.org> <- getText()) -> {
println(t)
}
</syntaxhighlight>
</lang>
 
=={{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.
<langsyntaxhighlight lang="scheme">
;; asynchronous call back definition
(define (success name text) (writeln 'Loaded name) (writeln text))
;;
(file->string success "http://www.google.com")
</syntaxhighlight>
</lang>
 
=={{header|Emacs Lisp}}==
<code>url.el</code> can download HTTP. <code>url-retrieve-synchronously</code> returns a buffer containing headers and body. Caller kills the buffer when no longer required.
 
{{libheader|url.el}}
<lang Lisp>(with-current-buffer
 
(url-retrieve-synchronously "http://www.rosettacode.org")
<code>url-retrieve-synchronously</code> returns a buffer containing headers and body. Caller must kill the buffer when no longer needed.
(goto-char (point-min))
 
(search-forward "\n\n" nil t) ;; skip headers
<syntaxhighlight lang="lisp">(let ((buffer (url-retrieve-synchronously "http://www.rosettacode.org")))
(prin1 (buffer-substring (point) (point-max)))
(unwind-protect
(kill-buffer (current-buffer)))</lang>
(with-current-buffer buffer
(message "%s" (buffer-substring url-http-end-of-headers (point-max))))
(kill-buffer buffer)))</syntaxhighlight>
 
Asynchronously (buffer doesn't need to be killed by caller):
 
<syntaxhighlight lang="lisp">(url-retrieve "http://www.rosettacode.org"
(lambda (_status)
(message "%s" (buffer-substring url-http-end-of-headers (point-max)))))</syntaxhighlight>
 
=={{header|Erlang}}==
===Synchronous===
<langsyntaxhighlight lang="erlang">
-module(main).
-export([main/1]).
Line 1,060 ⟶ 1,095:
{error, Res} -> io:fwrite("~p~n", [Res])
end.
</syntaxhighlight>
</lang>
 
===Asynchronous===
<langsyntaxhighlight lang="erlang">
-module(main).
-export([main/1]).
Line 1,075 ⟶ 1,110:
after 10000 -> io:fwrite("Timed out.~n",[])
end.
</syntaxhighlight>
</lang>
 
Using it
<langsyntaxhighlight lang="erlang">
|escript ./req.erl http://www.rosettacode.org
</syntaxhighlight>
</lang>
 
=={{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.
 
<langsyntaxhighlight lang="fsharp">
let wget (url : string) =
use c = new System.Net.WebClient()
Line 1,091 ⟶ 1,126:
 
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...
 
<langsyntaxhighlight lang="fsharp">
open System.Net
open System.IO
Line 1,110 ⟶ 1,145:
|> List.map wgetAsync
|> Async.Parallel
|> Async.RunSynchronously</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USE: http.client
"http://www.rosettacode.org" http-get nip print
</syntaxhighlight>
</lang>
 
=={{header|Forth}}==
{{works with|GNU Forth|0.7.0}}
This works at the socket level, returning both the HTTP headers and page contents.
<langsyntaxhighlight lang="forth">
include unix/socket.fs
 
Line 1,127 ⟶ 1,162:
dup pad 8092 read-socket type
close-socket
</syntaxhighlight>
</lang>
 
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">Dim As String urlfile
urlfile="start http://rosettacode.org/wiki/Main_Page"
 
Print urlfile
 
Shell(urlfile)
 
Print !"\n--- pulsa RETURN para continuar ---"
Sleep</syntaxhighlight>
 
 
=={{header|friendly interactive shell}}==
{{trans|UNIX Shell}}
<langsyntaxhighlight lang="fishshell">curl -s -L http://rosettacode.org/</langsyntaxhighlight>
 
<langsyntaxhighlight lang="fishshell">lynx -source http://rosettacode.org/</langsyntaxhighlight>
 
<langsyntaxhighlight lang="fishshell">wget -O - -q http://rosettacode.org/</langsyntaxhighlight>
 
<langsyntaxhighlight lang="fishshell">lftp -c "cat http://rosettacode.org/"</langsyntaxhighlight>
 
{{works with|BSD}}
<langsyntaxhighlight lang="fishshell">ftp -o - http://rosettacode.org ^ /dev/null</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="frink">
print[read["http://frinklang.org/"]]
</syntaxhighlight>
</lang>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
 
local fn URLSessionHandler( session as URLSessionRef, dta as CFDataRef, response as URLResponseRef, err as ErrorRef, userData as ptr )
if ( fn HTTPURLResponseStatusCode( (HTTPURLResponseRef)response ) == 200 )
NSLog( @"%@", fn StringWithData( dta, NSUTF8StringEncoding ) )
else
NSLog( @"%@", fn ErrorLocalizedDescription( err ) )
end if
NSLogScrollToTop
end fn
 
local fn URLSessionWithGetRequest( path as CFStringRef )
CFURLRef url = fn URLWithString( path )
MutableURLRequestRef urlRequest = fn MutableURLRequestWithURL( url )
MutableURLRequestSetHTTPMethod( urlRequest, @"HTTP" )
URLSessionRef session = fn URLSessionSharedSession
URLSessionDataTaskRef task = fn URLSessionDataTaskWithRequestCompletionHandler( session, urlRequest, @fn URLSessionHandler, NULL )
URLSessionTaskResume( task )
end fn
 
fn URLSessionWithGetRequest( @"http://rosettacode.org" )
 
HandleEvents
</syntaxhighlight>
 
=={{header|Gastona}}==
<langsyntaxhighlight lang="gastona">#listix#
 
<main>
LOOP, TEXT FILE, http://www.rosettacode.org
, BODY, @<value>
</syntaxhighlight>
</lang>
 
=={{header|GML}}==
Line 1,160 ⟶ 1,237:
 
'''Any Event'''
<langsyntaxhighlight lang="gml">get = http_get("http://www.rosettacode.org/");</langsyntaxhighlight>
 
'''HTTP Event'''
<langsyntaxhighlight lang="gml">if (ds_map_find_value(async_load,"id") == get)
{
show_message_async(ds_map_find_value(async_load,"result"));
}</langsyntaxhighlight>
 
=={{header|Go}}==
<syntaxhighlight lang="go">
<lang go>
package main
 
Line 1,186 ⟶ 1,263:
io.Copy(os.Stdout, r.Body)
}
</syntaxhighlight>
</lang>
 
Output:
Line 1,200 ⟶ 1,277:
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">
new URL("http://www.rosettacode.org").eachLine { println it }
</syntaxhighlight>
</lang>
 
=={{header|GUISS}}==
Line 1,208 ⟶ 1,285:
It would be more appropriate to paste to notepad:
 
<langsyntaxhighlight 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,
Menu:Edit,Paste</langsyntaxhighlight>
 
=={{header|Halon}}==
<langsyntaxhighlight lang="halon">echo http("http://www.rosettacode.org");</langsyntaxhighlight>
 
=={{header|Haskell}}==
Using {{libheader|HTTP}} from [http://hackage.haskell.org/packages/hackage.html HackageDB]
 
<langsyntaxhighlight lang="haskell">
import Network.Browser
import Network.HTTP
Line 1,229 ⟶ 1,306:
request $ getRequest "http://www.rosettacode.org/"
putStrLn $ rspBody $ snd rsp
</syntaxhighlight>
</lang>
 
== Icon and Unicon ==
==={{header|Icon}}===
<langsyntaxhighlight lang="icon">
link cfunc
procedure main(arglist)
Line 1,253 ⟶ 1,330:
while write(read(f))
end
</syntaxhighlight>
</lang>
 
Using it
<langsyntaxhighlight lang="icon">
|icon req.icn http://www.rosettacode.org
</syntaxhighlight>
</lang>
 
==={{header|Unicon}}===
Unicon provides improved socket and messaging support without the need for the external function ''cfunc'':
<langsyntaxhighlight lang="unicon">
procedure main(arglist)
m := open(arglist[1],"m")
while write(read(m))
end
</syntaxhighlight>
</lang>
 
=={{header|J}}==
Using <tt>gethttp</tt> from [[Web Scraping#J|Web Scraping]]
 
<langsyntaxhighlight lang="j">require'web/gethttp'
gethttp 'http://www.rosettacode.org'
</syntaxhighlight>
</lang>
 
=={{header|Java}}==
The ''URL'' class offers an ''openStream'' method which will make a connection and return an ''InputStream''.
<syntaxhighlight lang="java">
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
</syntaxhighlight>
<syntaxhighlight lang="java">
void printContent(String address) throws URISyntaxException, IOException {
URL url = new URI(address).toURL();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
String line;
while ((line = reader.readLine()) != null)
System.out.println(line);
}
}
</syntaxhighlight>
<br />
Using the standard [http://openjdk.java.net/groups/net/httpclient/ Java 11 HTTP Client]
 
<langsyntaxhighlight lang="java">import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
Line 1,297 ⟶ 1,394:
.join();
}
}</langsyntaxhighlight>
 
{{libheader|Apache Commons IO}}
 
<langsyntaxhighlight lang="java5">
import org.apache.commons.io.IOUtils;
import java.net.URL;
Line 1,309 ⟶ 1,406:
IOUtils.copy(new URL("http://rosettacode.org").openStream(),System.out);
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
 
===Browser===
Using fetch API and async/await:
<lang JavaScript>var req = new XMLHttpRequest();
<syntaxhighlight lang="javascript">
const response = await fetch('http://rosettacode.org');
const text = await response.text();
console.log(text);
</syntaxhighlight>
 
Using fetch API:
<syntaxhighlight lang="javascript">
fetch('http://rosettacode.org').then(function (response) {
return response.text();
}).then(function (text) {
console.log(text);
});
</syntaxhighlight>
 
<syntaxhighlight lang="javascript">var req = new XMLHttpRequest();
req.onload = function() {
console.log(this.responseText);
Line 1,320 ⟶ 1,433:
 
req.open('get', 'http://rosettacode.org', true);
req.send()</langsyntaxhighlight>
 
Using fetch API:
<lang JavaScript>
fetch('http://rosettacode.org').then(function(response) {
return response.text();
}).then(function(myText) {
console.log(myText);
});
</lang>
 
As a repeatable function:
 
<syntaxhighlight lang="javascript">/**
<lang JavaScript>/**
* @name _http
* @description Generic API Client using XMLHttpRequest
Line 1,397 ⟶ 1,501:
.join("&")
}
}</langsyntaxhighlight>
 
Using jQuery:
 
<langsyntaxhighlight JavaScriptlang="javascript">$.get('http://rosettacode.org', function(data) {
console.log(data);
};</langsyntaxhighlight>
 
===Node.js===
Line 1,409 ⟶ 1,513:
With Node.js, using only the included http module.
 
<langsyntaxhighlight lang="javascript">const http = require('http');
http.get('http://rosettacode.org', (resp) => {
Line 1,427 ⟶ 1,531:
}).on("error", (err) => {
console.log("Error: " + err.message);
});</langsyntaxhighlight>
 
=={{header|Jsish}}==
Based on Jsi_Wget that ships with Jsish.
 
<langsyntaxhighlight lang="javascript">#!/usr/bin/env jsish
function httpGet(fileargs:array|string, conf:object=void) {
Line 1,539 ⟶ 1,643:
 
if (isMain())
runModule(httpGet);</langsyntaxhighlight>
 
{{out}}
Line 1,560 ⟶ 1,664:
 
=={{header|Julia}}==
<langsyntaxhighlight Julialang="julia">readurl(url) = open(readlines, download(url))
 
readurl("http://rosettacode.org/index.html")</langsyntaxhighlight>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.net.URL
Line 1,577 ⟶ 1,681:
while (sc.hasNextLine()) println(sc.nextLine())
sc.close()
}</langsyntaxhighlight>
 
=={{header|Lasso}}==
incude_url is a wrapper for Lasso's curl datatype, however it can be achieved in several ways.
<langsyntaxhighlight Lassolang="lasso">// using include_url wrapper:
include_url('http://rosettacode.org/index.html')
 
Line 1,590 ⟶ 1,694:
local(x = curl('http://rosettacode.org/index'))
local(y = #x->result)
#y->asString</langsyntaxhighlight>
 
=={{header|LFE}}==
 
===Synchronous===
<langsyntaxhighlight lang="lisp">(: inets start)
(case (: httpc request '"http://lfe.github.io")
((tuple 'ok result)
Line 1,601 ⟶ 1,705:
((tuple 'error reason)
(: io format '"Error: ~p~n" (list reason))))
</syntaxhighlight>
</lang>
 
===Asynchronous===
<langsyntaxhighlight lang="lisp">(: inets start)
(let* ((method 'get)
(url '"http://lfe.github.io")
Line 1,617 ⟶ 1,721:
((tuple 'http (tuple request-id result))
(: io format '"Result: ~p~n" (list result))))))
</syntaxhighlight>
</lang>
 
=={{header|Liberty BASIC}}==
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")
timer 2000, [on]
Line 1,642 ⟶ 1,746:
close #url
end function
</syntaxhighlight>
</lang>
 
=={{header|Lingo}}==
Line 1,648 ⟶ 1,752:
 
Parent script "SimpleHttpGet":
<langsyntaxhighlight lang="lingo">property _netID
property _cbHandler
property _cbTarget
Line 1,677 ⟶ 1,781:
call(me._cbHandler, me._cbTarget, res, err)
end if
end</langsyntaxhighlight>
 
In some movie script:
<langsyntaxhighlight lang="lingo">----------------------------------------
--
----------------------------------------
Line 1,696 ⟶ 1,800:
put "Network Error:" && err
end if
end</langsyntaxhighlight>
 
Executed in the "Message Window" (=Director's interactive Lingo console):
<langsyntaxhighlight lang="lingo">getAdobeHomePage()
-- "<!doctype html>
...</langsyntaxhighlight>
 
=={{header|LiveCode}}==
Without a callback handler the get URL method will block until complete
<langsyntaxhighlight LiveCodelang="livecode">put true into libURLFollowHttpRedirects
get URL "http://httpbin.org/html"
put it</langsyntaxhighlight>
Non-blocking version
<langsyntaxhighlight LiveCodelang="livecode">on myUrlDownloadFinished
answer "Download Complete" with "Okay"
end myUrlDownloadFinished
Line 1,715 ⟶ 1,819:
command getWebResource
load URL "http://httpbin.org/html" with message "myUrlDownloadFinished"
end getWebResource</langsyntaxhighlight>
 
=={{header|LSL}}==
To test it yourself; rez a box on the ground, and add the following as a New Script.
<langsyntaxhighlight LSLlang="lsl">string sURL = "http://www.RosettaCode.Org";
key kHttpRequestId;
default {
Line 1,739 ⟶ 1,843:
}
}
</syntaxhighlight>
</lang>
Output:
<pre>Status=200
Line 1,764 ⟶ 1,868:
=={{header|Lua}}==
{{libheader|LuaSocket}}
<syntaxhighlight lang="lua">
<lang Lua>
local http = require("socket.http")
local url = require("socket.url")
local page = http.request('http://www.google.com/m/search?q=' .. url.escape("lua"))
print(page)
</syntaxhighlight>
</lang>
 
=={{header|M2000 Interpreter}}==
Line 1,778 ⟶ 1,882:
(some of them as read only)
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Declare xml "Microsoft.XMLHTTP"
Line 1,808 ⟶ 1,912:
}
CheckIt
</syntaxhighlight>
</lang>
 
=={{header|Maple}}==
In Maple 18 or later:
<syntaxhighlight lang="maple">
<lang Maple>
content := URL:-Get( "http://www.google.com/" );
</syntaxhighlight>
</lang>
 
In Maple 17 or earlier:
<syntaxhighlight lang="maple">
<lang Maple>
content := HTTP:-Get( "http://www.google.com/" );
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">
<lang Mathematica>
Print[Import["http://www.google.com/webhp?complete=1&hl=en", "Source"]]
</syntaxhighlight>
</lang>
 
=={{header|MATLAB}} / {{header|Octave}}==
Line 1,831 ⟶ 1,935:
 
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')
 
Line 1,837 ⟶ 1,941:
 
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].
 
=={{header|Microsoft Small Basic}}==
<syntaxhighlight lang="smallbasic">TextWindow.WriteLine(Network.GetWebPageContents("http://rosettacode.org"))</syntaxhighlight>
 
=={{header|MIRC Scripting Language}}==
Line 1,845 ⟶ 1,952:
 
=={{header|Nanoquery}}==
<langsyntaxhighlight lang="nanoquery">import http
import url
 
Line 1,853 ⟶ 1,960:
 
response = client.get(url.getFile())
println response.get("body")</langsyntaxhighlight>
 
=={{header|Nemerle}}==
<langsyntaxhighlight Nemerlelang="nemerle">using System;
using System.Console;
using System.Net;
Line 1,872 ⟶ 1,979:
myStream.Close()
}
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
Line 1,878 ⟶ 1,985:
An implementation of the [[#Java|Java]] version shown above; demonstrating NetRexx's ability to exploit the rich Java SDK.
 
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
 
Line 1,894 ⟶ 2,001:
end
 
return</langsyntaxhighlight>
 
=={{header|NewLisp}}==
<syntaxhighlight lang="newlisp">
<lang NewLisp>
(get-url "http://www.rosettacode.org")
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
Compile example with command <code>nim c -d:ssl httpClient.nim</code>.
<lang nim>import httpclient
<syntaxhighlight lang="nim">import httpclient
 
var client = newHttpClient()
echo client.getContent "http://rosettacode.org"</langsyntaxhighlight>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">use HTTP;
use Collection;
 
Line 1,918 ⟶ 2,026:
};
}
}</langsyntaxhighlight>
 
=={{header|Objective-C}}==
<langsyntaxhighlight lang="objc">#import <Foundation/Foundation.h>
 
int main (int argc, const char * argv[]) {
Line 1,937 ⟶ 2,045:
}
return 0;
}</langsyntaxhighlight>
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">
let () =
let url = "http://www.rosettacode.org" in
Line 1,946 ⟶ 2,054:
print_endline page_content;
;;
</syntaxhighlight>
</lang>
 
The source code of the function ''make_request'' is [[Web_Scraping/OCaml|here]].
Line 1,953 ⟶ 2,061:
{{libheader|libcurl}}
 
<langsyntaxhighlight lang="scheme">
(import (lib curl))
 
Line 1,959 ⟶ 2,067:
(curl 'url "http://rosettacode.org/")
(curl 'perform)
</syntaxhighlight>
</lang>
 
=={{header|ooRexx}}==
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!
<langsyntaxhighlight lang="oorexx">url=.bsf~new("java.net.URL","http://teletext.orf.at")
sc =.bsf~new("java.util.Scanner",url~openStream)
loop while sc~hasNext
say sc~nextLine
End
::requires BSF.CLS -- get Java camouflaging support</langsyntaxhighlight>
{{out}}
massaged to avoid problems.
Line 1,978 ⟶ 2,086:
=={{header|Oz}}==
When creating a file object, it is possible to specify an URL instead of a filename:
<syntaxhighlight lang="oz">
<lang oz>
declare
fun {GetPage Url}
Line 1,989 ⟶ 2,097:
in
{System.showInfo {GetPage "http://www.rosettacode.org"}}
</syntaxhighlight>
</lang>
 
{{libheader|OzHttpClient}}
 
If you need more fine-grained control of the request, you could use a custom library:
<syntaxhighlight lang="oz">
<lang oz>
declare
[HTTPClient] = {Module.link ['x-ozlib://mesaros/net/HTTPClient.ozf']}
Line 2,012 ⟶ 2,120:
in
{System.showInfo {GetPage "http://www.rosettacode.org"}}
</syntaxhighlight>
</lang>
 
=={{header|Pascal}}==
{{works with|Free Pascal}}
Using [http://wiki.freepascal.org/fphttpclient fphttpclient]
<langsyntaxhighlight lang="pascal">{$mode objfpc}{$H+}
uses fphttpclient;
 
Line 2,032 ⟶ 2,140:
end;
writeln(s)
end.</langsyntaxhighlight>
 
 
{{works with|Free Pascal}} {{libheader|CThreads}} {{libheader|Classes}} {{libheader|httpsend}}
<langsyntaxhighlight lang="pascal">program http;
 
{$mode objfpc}{$H+}
Line 2,082 ⟶ 2,190:
Readln;
 
end.</langsyntaxhighlight>
 
=={{header|Peloton}}==
English dialect, short form:
<langsyntaxhighlight lang="sgml">
<@ SAYURLLIT>http://rosettacode.org/wiki/Main_Page</@>
</syntaxhighlight>
</lang>
 
English dialect, padded variable-length form:
<langsyntaxhighlight lang="sgml">
<# SAY URLSOURCE LITERAL>http://rosettacode.org/wiki/Main_Page</#>
</syntaxhighlight>
</lang>
 
=={{header|Perl}}==
Line 2,104 ⟶ 2,212:
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]].
 
<langsyntaxhighlight lang="perl">use strict; use warnings;
require 5.014; # check HTTP::Tiny part of core
use HTTP::Tiny;
 
print( HTTP::Tiny->new()->get( 'http://rosettacode.org')->{content} );</langsyntaxhighlight>
 
===Library examples===
Line 2,117 ⟶ 2,225:
Classic LWP sample.
 
<langsyntaxhighlight lang="perl">use LWP::Simple qw/get $ua/;
$ua->agent(undef) ; # cloudflare blocks default LWP agent
print( get("http://www.rosettacode.org") );</langsyntaxhighlight>
 
or with more error-checking
 
<langsyntaxhighlight lang="perl">use strict;
use LWP::UserAgent;
 
Line 2,131 ⟶ 2,239:
$response->is_success or die "Failed to GET '$url': ", $response->status_line;
 
print $response->as_string</langsyntaxhighlight>
 
=={{header|Phix}}==
{{libheader|Phix/libcurl}}
Note that curl_easy_get_file() is better suited to multi-megabyte downloads than curl_easy_perform_ex().
<!--<langsyntaxhighlight Phixlang="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: #7060A8;">curl_global_init<span style="color: #0000FF;">(<span style="color: #0000FF;">)</span>
Line 2,146 ⟶ 2,254:
<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;">)
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,160 ⟶ 2,268:
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php">
readfile("http://www.rosettacode.org");
</syntaxhighlight>
</lang>
 
=={{header|PicoLisp}}==
<syntaxhighlight lang="picolisp">
<lang PicoLisp>
(load "@lib/http.l")
 
(client "rosettacode.org" 80 NIL # Connect to rosettacode
(out NIL (echo)) ) # Echo to standard output
</syntaxhighlight>
</lang>
 
=={{header|Pike}}==
<langsyntaxhighlight lang="pike">
write("%s",Protocols.HTTP.get_url_data("http://www.rosettacode.org"));
</syntaxhighlight>
</lang>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">
Invoke-WebRequest 'http://www.rosettacode.org'
</syntaxhighlight>
 
<syntaxhighlight lang="powershell">
$wc = New-Object Net.WebClient
$wc.DownloadString('http://www.rosettacode.org')
</syntaxhighlight>
</lang>
 
=={{header|Prolog}}==
Works with SWI-Prolog and library http/http_open. (Extract from the doc).
 
<syntaxhighlight lang="prolog">
<lang Prolog>
:- use_module(library( http/http_open )).
 
Line 2,193 ⟶ 2,305:
copy_stream_data(In, user_output),
close(In).
</syntaxhighlight>
</lang>
 
=={{header|PureBasic}}==
<syntaxhighlight lang="purebasic">
<lang PureBasic>
InitNetwork()
OpenConsole()
Line 2,214 ⟶ 2,326:
DeleteFile(filename$)
EndIf
</syntaxhighlight>
</lang>
 
Another solution using general networking commands
<syntaxhighlight lang="purebasic">
<lang PureBasic>
InitNetwork()
OpenConsole()
Line 2,232 ⟶ 2,344:
; next line only to prevent console from closing on Windows
Input()
</syntaxhighlight>
</lang>
 
Of course you could use wget too.
Line 2,240 ⟶ 2,352:
;Python 3:
Using the [http://docs.python.org/py3k/library/urllib.request.html urllib.request] module.
<langsyntaxhighlight lang="python">
import urllib.request
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.
<langsyntaxhighlight lang="python">
from http.client import HTTPConnection
conn = HTTPConnection("example.com")
Line 2,254 ⟶ 2,366:
result = conn.getresponse()
r1 = result.read() # This retrieves the entire contents.
</syntaxhighlight>
</lang>
 
;Python 2:
Using the [http://docs.python.org/library/urllib.html urllib] library.
<langsyntaxhighlight lang="python">
import urllib
print urllib.urlopen("http://rosettacode.org").read()
</syntaxhighlight>
</lang>
 
Using the [http://docs.python.org/library/urllib2.html urllib2] library.
<langsyntaxhighlight lang="python">
import urllib2
print urllib2.urlopen("http://rosettacode.org").read()
</syntaxhighlight>
</lang>
 
 
{{libheader|Requests}}
{{works with|Python|2.7, 3.4–3.7}}
<syntaxhighlight lang="python">
<lang Python>
import requests
print(requests.get("http://rosettacode.org").text)
</syntaxhighlight>
</lang>
 
=={{header|R}}==
Line 2,283 ⟶ 2,395:
First, retrieve the webpage.
 
<syntaxhighlight lang="r">
<lang R>
library(RCurl)
webpage <- getURL("http://rosettacode.org")
Line 2,294 ⟶ 2,406:
.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!
</syntaxhighlight>
</lang>
 
Now parse the html code into a tree and print the html.
 
<syntaxhighlight lang="r">
<lang R>
library(XML)
pagetree <- htmlTreeParse(webpage )
pagetree$children$html
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
(require net/url)
Line 2,311 ⟶ 2,423:
#:redirections 100)
(current-output-port))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 2,318 ⟶ 2,430:
Using LWP::Simple from [https://modules.raku.org/search/?q=LWP%3A%3ASimple the Raku ecosystem].
 
<syntaxhighlight lang="raku" perl6line>use v6LWP::Simple;
 
use LWP::Simple;
 
print LWP::Simple.get("http://www.rosettacode.org");
</syntaxhighlight>
</lang>
 
or, without LWP::Simple:
 
<syntaxhighlight lang="raku" line>my $socket = IO::Socket::INET.new(host => "www.rosettacode.org",
<lang perl6>use v6;
 
my $socket = IO::Socket::INET.new(host => "www.rosettacode.org",
port => 80,);
$socket.print("GET / HTTP/1.0\r\n\r\n");
print $socket.recv();
$socket.close;
</syntaxhighlight>
</lang>
 
=={{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.
<syntaxhighlight lang="realbasic">
<lang REALbasic>
Dim sock As New HTTPSocket
Print(sock.Get("http://www.rosettacode.org", 10)) //set the timeout period to 10 seconds.
</syntaxhighlight>
</lang>
 
=={{header|REBOL}}==
<syntaxhighlight lang="rebol">
<lang REBOL>
print read http://rosettacode.org
</syntaxhighlight>
</lang>
 
=={{header|REXX}}==
Line 2,352 ⟶ 2,460:
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.
 
<langsyntaxhighlight Rexxlang="rexx">/* ft=rexx */
/* GET2.RX - Display contents of an URL on the terminal. */
/* Usage: rexx get.rx http://rosettacode.org */
parse arg url .
'curl' url</langsyntaxhighlight>
 
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.)
 
<langsyntaxhighlight Rexxlang="rexx">/* ft=rexx */
/* GET2.RX - Display contents of an URL on the terminal. */
/* Usage: rexx get2.rx http://rosettacode.org */
Line 2,367 ⟶ 2,475:
do i = 1 to stuff.0
say stuff.i
end</langsyntaxhighlight>
 
Another simple change redirects the output to another external program like a shell pipe.
 
<langsyntaxhighlight Rexxlang="rexx">/* ft=rexx */
/* GET3.RX - Display contents of an URL on the terminal. */
/* Usage: rexx get3.rx http://rosettacode.org */
parse arg url .
address system 'curl' url with output fifo ''
address system 'more' with input fifo ''</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
See download("http://rosettacode.org")
</syntaxhighlight>
</lang>
 
=={{header|RLaB}}==
Line 2,408 ⟶ 2,516:
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)
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,419 ⟶ 2,527:
x = readm(url);
close (url);
</syntaxhighlight>
</lang>
 
=={{header|Ruby}}==
The simple way loads the entire content into memory, then prints it.
 
<langsyntaxhighlight lang="ruby">
require 'open-uri'
 
print open("http://rosettacode.org") {|f| f.read}
</syntaxhighlight>
</lang>
 
If the content might be large, the better way uses FileUtils.copy_stream.
 
<langsyntaxhighlight lang="ruby">
require 'fileutils'
require 'open-uri'
 
open("http://rosettacode.org/") {|f| FileUtils.copy_stream(f, $stdout)}
</syntaxhighlight>
</lang>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">print httpget$("http://rosettacode.org/wiki/Main_Page")</langsyntaxhighlight>
 
=={{header|Rust}}==
Cargo.toml
<langsyntaxhighlight lang="toml">
[dependencies]
hyper = "0.6"
</syntaxhighlight>
</lang>
src/main.rs
<langsyntaxhighlight lang="rust">
//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
Line 2,464 ⟶ 2,572:
println!("{}", body);
}
</syntaxhighlight>
</lang>
 
=={{header|Scala}}==
{{libheader|Scala}}
<langsyntaxhighlight lang="scala">import scala.io.Source
 
object HttpTest extends App {
Line 2,474 ⟶ 2,582:
 
Source.fromURL("http://www.rosettacode.org").getLines.foreach(println)
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
{{works with|Guile}}
 
<langsyntaxhighlight lang="scheme">
; Use the regular expression module to parse the url (included with Guile)
(use-modules (ice-9 regex))
Line 2,506 ⟶ 2,614:
(do ((c (read-char s) (read-char s))) ((eof-object? c))
(display c)))
</syntaxhighlight>
</lang>
{{works with|Chicken Scheme}}
Using the [http://api.call-cc.org/doc/http-client http-client] library, this is trivial.
<langsyntaxhighlight lang="scheme">
(use http-client)
(print
(with-input-from-request "http://google.com/"
#f read-string))
</syntaxhighlight>
</lang>
 
=={{header|Seed7}}==
Line 2,521 ⟶ 2,629:
which gets data specified by an URL using the HTTP protocol.
 
<langsyntaxhighlight lang="seed7">
$ include "seed7_05.s7i";
include "gethttp.s7i";
Line 2,528 ⟶ 2,636:
begin
writeln(getHttp("www.rosettacode.org"));
end func;</langsyntaxhighlight>
 
=={{header|SenseTalk}}==
<langsyntaxhighlight lang="sensetalk">put url "http://www.rosettacode.org"</langsyntaxhighlight>
 
=={{header|Sidef}}==
Sidef can load and use Perl modules:
<syntaxhighlight lang ="ruby">func getrequire(url'HTTP::Tiny') {
 
var lwp = (
func get(url) {
try { require('LWP::UserAgent') }
static ua = %O<HTTP::Tiny>.new(agent => 'Mozilla/5.0')
catch { warn "'LWP::UserAgent' is not installed!"; return nil }
var resp = ua.get(url)
)
if (resp{:success}) {
var ua = lwp.new(agent => 'Mozilla/5.0')
if (var resp = ua.get(url);return resp{:content}.is_success) {decode_utf8
return resp.decoded_content
}
return nil
}
 
printsay get("http://rosettacode.org")</langsyntaxhighlight>
 
=={{header|Smalltalk}}==
{{works with|Pharo}}
<langsyntaxhighlight lang="smalltalk">
Transcript show: 'http://rosettacode.org' asUrl retrieveContents contentStream.
</syntaxhighlight>
</lang>
 
=={{header|SNOBOL4}}==
{{works with|Macro SNOBOL4 in C}}
<langsyntaxhighlight lang="snobol">-include "tcp.sno"
tcp.open(.conn,'www.rosettacode.org','http') :s(cont1)
terminal = "cannot open" :(end)
Line 2,564 ⟶ 2,671:
tcp.close(.conn)
end
</syntaxhighlight>
</lang>
 
=={{header|Swift}}==
<langsyntaxhighlight Swiftlang="swift">import Foundation
 
let request = NSURLRequest(URL: NSURL(string: "http://rosettacode.org/")!)
Line 2,581 ⟶ 2,688:
}
 
CFRunLoopRun() // dispatch</langsyntaxhighlight>
 
=={{header|Tcl}}==
Note that the <code>http</code> package is distributed as part of Tcl.
 
<langsyntaxhighlight lang="tcl">
package require http
set request [http::geturl "http://www.rosettacode.org"]
puts [http::data $request]
http::cleanup $request</langsyntaxhighlight>
 
=={{header|TSE SAL}}==
<syntaxhighlight lang="tse sal">
<lang TSE SAL>
 
DLL "<urlmon.dll>"
Line 2,619 ⟶ 2,726:
END
 
</syntaxhighlight>
</lang>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
SET DATEN = REQUEST ("http://www.rosettacode.org")
*{daten}
</syntaxhighlight>
</lang>
 
=={{header|UNIX Shell}}==
<langsyntaxhighlight lang="bash">curl -s -L http://rosettacode.org/</langsyntaxhighlight>
 
<langsyntaxhighlight lang="bash">lynx -source http://rosettacode.org/</langsyntaxhighlight>
 
<langsyntaxhighlight lang="bash">wget -O - -q http://rosettacode.org/</langsyntaxhighlight>
 
<langsyntaxhighlight lang="bash">lftp -c "cat http://rosettacode.org/"</langsyntaxhighlight>
 
{{works with|BSD}}
<langsyntaxhighlight lang="bash">ftp -o - http://rosettacode.org 2>/dev/null</langsyntaxhighlight>
 
=={{header|VBScript}}==
Line 2,644 ⟶ 2,751:
 
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
 
Line 2,662 ⟶ 2,769:
 
Set oHTTP = Nothing
</syntaxhighlight>
</lang>
 
=={{header|Visual Basic}}==
Line 2,671 ⟶ 2,778:
{{works with|VBA|6.5}}
{{works with|VBA|7.1}}
<langsyntaxhighlight lang="vb">Sub Main()
Dim HttpReq As WinHttp.WinHttpRequest
' in the "references" dialog of the IDE, check
Line 2,685 ⟶ 2,792:
HttpReq.Send
Debug.Print HttpReq.ResponseText
End Sub</langsyntaxhighlight>
 
=={{header|Visual Basic .NET}}==
<langsyntaxhighlight lang="vbnet">
Imports System.Net
 
Line 2,694 ⟶ 2,801:
Dim content As String = client.DownloadString("http://www.google.com")
Console.WriteLine(content)
</syntaxhighlight>
</lang>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="Vlang">
import net.http
 
fn main() {
resp := http.get("http://rosettacode.org/robots.txt") or {println(err) exit(-1)}
println(resp.body.str())
}
</syntaxhighlight>
 
=={{header|Wren}}==
{{trans|C}}
{{libheader|libcurl}}
An embedded program so we can ask the C host to communicate with libcurl for us.
<syntaxhighlight lang="wren">/* HTTP.wren */
 
var CURLOPT_URL = 10002
var CURLOPT_FOLLOWLOCATION = 52
var CURLOPT_ERRORBUFFER = 10010
 
foreign class Curl {
construct easyInit() {}
 
foreign easySetOpt(opt, param)
 
foreign easyPerform()
 
foreign easyCleanup()
}
 
var curl = Curl.easyInit()
if (curl == 0) {
System.print("Error initializing cURL.")
return
}
curl.easySetOpt(CURLOPT_URL, "http://www.rosettacode.org/")
curl.easySetOpt(CURLOPT_FOLLOWLOCATION, 1)
curl.easySetOpt(CURLOPT_ERRORBUFFER, 0) // buffer to be supplied by C
 
var status = curl.easyPerform()
if (status != 0) {
System.print("Failed to perform task.")
return
}
curl.easyCleanup()</syntaxhighlight>
<br>
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 <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "wren.h"
 
/* C <=> Wren interface functions */
 
void C_curlAllocate(WrenVM* vm) {
CURL** pcurl = (CURL**)wrenSetSlotNewForeign(vm, 0, 0, sizeof(CURL*));
*pcurl = curl_easy_init();
}
 
void C_easyPerform(WrenVM* vm) {
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0);
CURLcode cc = curl_easy_perform(curl);
wrenSetSlotDouble(vm, 0, (double)cc);
}
 
void C_easyCleanup(WrenVM* vm) {
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0);
curl_easy_cleanup(curl);
}
 
void C_easySetOpt(WrenVM* vm) {
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0);
CURLoption opt = (CURLoption)wrenGetSlotDouble(vm, 1);
if (opt < 10000) {
long lparam = (long)wrenGetSlotDouble(vm, 2);
curl_easy_setopt(curl, opt, lparam);
} else {
if (opt == CURLOPT_URL) {
const char *url = wrenGetSlotString(vm, 2);
curl_easy_setopt(curl, opt, url);
} else if (opt == CURLOPT_ERRORBUFFER) {
char buffer[CURL_ERROR_SIZE];
curl_easy_setopt(curl, opt, buffer);
}
}
}
 
WrenForeignClassMethods bindForeignClass(WrenVM* vm, const char* module, const char* className) {
WrenForeignClassMethods methods;
methods.allocate = NULL;
methods.finalize = NULL;
if (strcmp(module, "main") == 0) {
if (strcmp(className, "Curl") == 0) {
methods.allocate = C_curlAllocate;
}
}
return methods;
}
 
WrenForeignMethodFn bindForeignMethod(
WrenVM* vm,
const char* module,
const char* className,
bool isStatic,
const char* signature) {
if (strcmp(module, "main") == 0) {
if (strcmp(className, "Curl") == 0) {
if (!isStatic && strcmp(signature, "easySetOpt(_,_)") == 0) return C_easySetOpt;
if (!isStatic && strcmp(signature, "easyPerform()") == 0) return C_easyPerform;
if (!isStatic && strcmp(signature, "easyCleanup()") == 0) return C_easyCleanup;
}
}
return NULL;
}
 
static void writeFn(WrenVM* vm, const char* text) {
printf("%s", text);
}
 
void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) {
switch (errorType) {
case WREN_ERROR_COMPILE:
printf("[%s line %d] [Error] %s\n", module, line, msg);
break;
case WREN_ERROR_STACK_TRACE:
printf("[%s line %d] in %s\n", module, line, msg);
break;
case WREN_ERROR_RUNTIME:
printf("[Runtime Error] %s\n", msg);
break;
}
}
 
char *readFile(const char *fileName) {
FILE *f = fopen(fileName, "r");
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
rewind(f);
char *script = malloc(fsize + 1);
fread(script, 1, fsize, f);
fclose(f);
script[fsize] = 0;
return script;
}
 
int main(int argc, char **argv) {
WrenConfiguration config;
wrenInitConfiguration(&config);
config.writeFn = &writeFn;
config.errorFn = &errorFn;
config.bindForeignClassFn = &bindForeignClass;
config.bindForeignMethodFn = &bindForeignMethod;
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "HTTP.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
switch (result) {
case WREN_RESULT_COMPILE_ERROR:
printf("Compile Error!\n");
break;
case WREN_RESULT_RUNTIME_ERROR:
printf("Runtime Error!\n");
break;
case WREN_RESULT_SUCCESS:
break;
}
wrenFreeVM(vm);
free(script);
return 0;
}</syntaxhighlight>
 
=={{header|X86-64 Assembly}}==
===UASM 5.52===
The same as the [[Sockets]] example, Just with a read method added...
<syntaxhighlight lang="asm">
option casemap:none
option literals:on
 
ifndef __SOCKET_CLASS__
__SOCKET_CLASS__ equ 1
if @Platform eq windows64
WSADATA struct
wVersion dw ?
wHighVersion dw ?
iMaxSockets dw ?
iMaxUdpDg dw ?
szDescription db 256 dup (?)
szSystemStatus db 128 dup (?)
lpVendorInfo dq ?
WSADATA ends
option dllimport:<kernel32>
ExitProcess proto :word
HeapAlloc proto :qword, :dword, :qword
HeapFree proto :qword, :dword, :qword
GetProcessHeap proto
option dllimport:<ws2_32>
WSAStartup proto :word, :qword
WSACleanup proto :qword
closesocket proto :dword
option dllimport:none
exit equ ExitProcess
close equ closesocket
elseif @Platform eq linux64
malloc proto SYSTEMV :qword
free proto SYSTEMV :qword
close proto SYSTEMV :dword
exit proto SYSTEMV :dword
endif
memset proto :qword, :dword, :dword
printf proto :qword, :vararg
strlen proto :qword
getaddrinfo proto :qword, :qword, :qword, :qword
gai_strerror proto :dword
send proto :dword, :qword, :qword, :dword
recv proto :dword, :qword, :qword, :dword
socket proto :dword, :dword, :dword
connect proto :dword, :qword, :dword
freeaddrinfo proto :qword
 
CLASS socket_class
CMETHOD conn
CMETHOD write
CMETHOD read
ENDMETHODS
if @Platform eq windows64
wsa WSADATA <?>
endif
sock dd 0
pai dq 0
hostname dq ?
port dq ?
ENDCLASS
 
METHOD socket_class, Init, <VOIDARG>, <>, h:qword, p:qword
mov rbx, thisPtr
assume rbx:ptr socket_class
mov rax, h
mov [rbx].hostname, rax
mov rax, p
mov [rbx].port, rax
mov rax, rbx
assume rbx:nothing
ret
ENDMETHOD
 
METHOD socket_class, conn, <dword>, <>
local ht:qword
 
mov rbx, thisPtr
assume rbx:ptr socket_class
invoke printf, CSTR("--> Attempting connection to %s on %s",10), [rbx].hostname ,[rbx].port
if @Platform eq windows64
invoke WSAStartup, 202h, addr [rbx].wsa
endif
invoke memset, ht, 0, 0x30 ;; sizeof(struct addrinfo)
mov rax, ht
mov dword ptr [rax], 0 ;; ai_flags
mov dword ptr [rax+4], AF_INET
mov dword ptr [rax+8], SOCK_STREAM
invoke getaddrinfo, [rbx].hostname, [rbx].port, ht, addr [rbx].pai
.if rax != 0
invoke gai_strerror, eax
invoke printf, CSTR("--> Gai_strerror returned: %s",10), rax
mov rax, -1
jmp _exit
.endif
mov rax, [rbx].pai
mov edx, dword ptr [rax + 0XC] ;; pai.ai_protocol
mov ecx, dword ptr [rax + 8] ;; pai.ai_socktype
mov eax, dword ptr [rax + 4] ;; pai.ai_family
invoke socket, eax, ecx, edx
.if rax == -1
mov rax, -1
jmp _exit
.endif
mov [rbx].sock, eax
invoke printf, CSTR("--> Socket created as: %d",10), [rbx].sock
mov rax, [rbx].pai
mov edx, dword ptr [rax + 0x10] ;; pai.ai_addrlen
mov rcx, qword ptr [rax + 0x18] ;; pai.ai_addr
invoke connect, [rbx].sock, rcx, edx
.if rax == -1
invoke printf, CSTR("--> connect failed.. %i",10), rax
mov rax, -1
jmp _exit
.endif
mov rax, 0
 
_exit:
assume rbx:nothing
ret
ENDMETHOD
 
METHOD socket_class, write, <dword>, <>, b:qword
local tmp:qword
mov rbx, thisPtr
assume rbx:ptr socket_class
mov rax, b
mov tmp, rax
invoke strlen, tmp
mov rdx, rax
invoke send, [rbx].sock, tmp, rdx, 0
.if eax == -1
invoke printf, CSTR("--> Error in send..%d",10), rax
ret
.endif
assume rbx:nothing
ret
ENDMETHOD
 
METHOD socket_class, read, <VOIDARG>, <>, b:qword
local tmp:qword
 
mov rbx, thisPtr
assume rbx:ptr socket_class
mov rax, b
mov tmp, rax
invoke recv, [rbx].sock, tmp,MAX_READ_BYTES, 0
push rax
mov rax, tmp
mov b, rax
pop rax
invoke printf, CSTR("--> recv called, got %d bytes..",10), rax
assume rbx:nothing
ret
ENDMETHOD
 
METHOD socket_class, Destroy, <VOIDARG>, <>
mov rbx, thisPtr
assume rbx:ptr socket_class
invoke close, [rbx].sock
if @Platform eq windows64
invoke WSACleanup, addr [rbx].wsa
endif
.if [rbx].pai != 0
invoke freeaddrinfo, [rbx].pai
.endif
assume rbx:nothing
ret
ENDMETHOD
endif ;; __SOCKET_CLASS__
 
MAX_READ_BYTES equ 4023
 
.code
main proc
local lpSocket:ptr socket_class
local buffer:qword
 
mov lpSocket, _NEW(socket_class, CSTR("www.google.com"), CSTR("80"))
lpSocket->conn()
.if rax == -1
invoke exit, 0
ret
.endif
invoke printf, CSTR("-> Connected, sending data.",10)
lpSocket->write(CSTR("GET / HTTP 1.0",13,10,"Accept: text/html",13,10,13,10))
MEMALLOC(MAX_READ_BYTES)
mov buffer, rax
lpSocket->read(buffer)
invoke printf, CSTR("%s"), buffer
MEMFREE(buffer)
_DELETE(lpSocket)
invoke exit, 0
ret
main endp
 
end
</syntaxhighlight>
 
=={{header|zkl}}==
File htmlGet.zkl. This uses HTTP/1.0 Protocol to avoid chunked data. Or use cURL (see https example).
<langsyntaxhighlight lang="zkl">url := ask(0,"URL: ");
 
host := url;
Line 2,711 ⟶ 3,200:
server.write(get);
data := server.read(True);
println(data.text);</langsyntaxhighlight>
zkl htmlGet.zkl rosettacode.org/wiki/HTTP
{{out}}
Line 2,747 ⟶ 3,236:
 
=={{header|Zoea}}==
<syntaxhighlight lang="zoea">
<lang Zoea>
program: http
input: 'https://zoea.co.uk/examples/test.txt'
output: 'hello from zoea'
</syntaxhighlight>
</lang>
 
=={{header|Zoea Visual}}==
[http://zoea.co.uk/examples/zv-rc/Http.png HTTP]
 
=={{header|Zsh}}==
<langsyntaxhighlight lang="zsh">
zmodload zsh/net/tcp
ztcp example.com 80
Line 2,761 ⟶ 3,253:
while read -u $fd -r -e -t 1; do; :; done
ztcp -c $fd
</syntaxhighlight>
</lang>
 
{{omit from|Applesoft BASIC|No TCP/IP network support on Apple II}}
{{omit from|Brainf***}}
{{omit from|Commodore BASIC|Does not have network access}}
{{omit from|EasyLang|Has no internet functions}}
{{omit from|Inform 7|Does not have network access.}}
{{omit from|Integer BASIC|No TCP/IP network support on Apple II}}
9,476

edits