HTTP: Difference between revisions
m
→{{header|Wren}}: Minor tidy
(Initial FutureBasic task solution added) |
m (→{{header|Wren}}: Minor tidy) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1,411:
===Browser===
Using fetch API and async/await:▼
<syntaxhighlight lang="javascript">▼
const response = await fetch('http://rosettacode.org');
</syntaxhighlight>▼
Using fetch API:
<syntaxhighlight lang="javascript">
fetch('http://rosettacode.org').then(function (response) {▼
return response.text();
console.log(text);
});▼
</syntaxhighlight>
<syntaxhighlight lang="javascript">var req = new XMLHttpRequest();
req.onload = function() {
Line 1,418 ⟶ 1,434:
req.open('get', 'http://rosettacode.org', true);
req.send()</syntaxhighlight>
▲Using fetch API:
▲<syntaxhighlight lang="javascript">
▲fetch('http://rosettacode.org').then(function(response) {
▲ return response.text();
▲}).then(function(myText) {
▲ console.log(myText);
▲});
▲</syntaxhighlight>
As a repeatable function:
Line 2,279 ⟶ 2,286:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
Invoke-WebRequest 'http://www.rosettacode.org'
</syntaxhighlight>
<syntaxhighlight lang="powershell">
$wc = New-Object Net.WebClient
Line 2,632 ⟶ 2,643:
=={{header|Sidef}}==
Sidef can load and use Perl modules:
<syntaxhighlight lang="ruby">
var lwp = (▼
func get(url) {
if (resp{:success}) {
▲ var ua = lwp.new(agent => 'Mozilla/5.0')
}
return nil
}
=={{header|Smalltalk}}==
Line 2,807 ⟶ 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,840 ⟶ 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,950 ⟶ 2,960:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
|