HTTP: Difference between revisions
m
→{{header|Wren}}: Minor tidy
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
m (→{{header|Wren}}: Minor tidy) |
||
(11 intermediate revisions by 7 users not shown) | |||
Line 1,194:
<syntaxhighlight lang="frink">
print[read["http://frinklang.org/"]]
</syntaxhighlight>
=={{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>
Line 1,325 ⟶ 1,354:
=={{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]
Line 1,362 ⟶ 1,411:
===Browser===
Using fetch API and async/await:
<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() {
Line 1,369 ⟶ 1,434:
req.open('get', 'http://rosettacode.org', true);
req.send()</syntaxhighlight>
As a repeatable function:
Line 1,888 ⟶ 1,944:
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,950 ⟶ 2,009:
=={{header|Nim}}==
Compile example with command <code>nim c -d:ssl httpClient.nim</code>.
<syntaxhighlight lang="nim">import httpclient
Line 2,226 ⟶ 2,286:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
Invoke-WebRequest 'http://www.rosettacode.org'
</syntaxhighlight>
<syntaxhighlight lang="powershell">
$wc = New-Object Net.WebClient
Line 2,579 ⟶ 2,643:
=={{header|Sidef}}==
Sidef can load and use Perl modules:
<syntaxhighlight lang="ruby">
func get(url) {
static ua = %O<HTTP::Tiny>.new(agent => 'Mozilla/5.0')
var resp = ua.get(url)
if (resp{:success}) {
}
return nil
}
=={{header|Smalltalk}}==
Line 2,738 ⟶ 2,801:
Dim content As String = client.DownloadString("http://www.google.com")
Console.WriteLine(content)
</syntaxhighlight>
=={{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>
Line 2,744 ⟶ 2,817:
{{libheader|libcurl}}
An embedded program so we can ask the C host to communicate with libcurl for us.
<syntaxhighlight lang="
var CURLOPT_URL = 10002
Line 2,777 ⟶ 2,850:
<br>
We now embed this in the following C program, compile and run it.
<syntaxhighlight lang="c">/* gcc
#include <stdio.h>
Line 2,887 ⟶ 2,960:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 3,185 ⟶ 3,258:
{{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}}
|