HTTPS: Difference between revisions

m
imported>Marwal
m (→‎{{header|Wren}}: Minor tidy)
 
(3 intermediate revisions by 2 users not shown)
Line 381:
=={{header|JavaScript}}==
=== Browser ===
Using fetch API and async/await:
<syntaxhighlight lang="javascript">
varconst urlresponse = await fetch('https://rosettacode.org');
const text = await response.text();
console.log(text);
</syntaxhighlight>
 
 
 
<syntaxhighlight lang="javascript">fetch("https://sourceforge.net").then(function (response) {
return response.text();
Line 386 ⟶ 395:
return body;
});</syntaxhighlight>
 
=== Node.js ===
<syntaxhighlight lang="javascript">require("https").get("https://sourceforge.net", function (resp) {
Line 677 ⟶ 687:
 
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
Invoke-WebRequest 'https://www.rosettacode.org'
</syntaxhighlight>
 
<syntaxhighlight lang="powershell">
$wc = New-Object Net.WebClient
Line 846 ⟶ 860:
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var lwp = require('LWP::UserAgent'); # LWP::Protocol::https is needed
require('LWP::Protocol::https')
var url = 'https://rosettacode.org';
 
func get(url) {
var ua = lwp.new(
static ua = %O<LWP::UserAgent>.new(
agent agent => 'Mozilla/5.0',
ssl_opts => Hash.new(verify_hostname => 1),
);
)
var resp = ua.get(url);
if (resp.is_success) {
return resp.decoded_content
}
resp.is_success || die "Failed to GET #{url.dump}: #{resp.status_line}";
}
 
say get("https://rosettacode.org")</syntaxhighlight>
var resp = ua.get(url);
resp.is_success || die "Failed to GET #{url.dump}: #{resp.status_line}";
print resp.decoded_content;</syntaxhighlight>
 
=={{header|Swift}}==
Line 975 ⟶ 994:
{{libheader|libcurl}}
An embedded program so we can ask the C host to communicate with libcurl for us.
<syntaxhighlight lang="ecmascriptwren">/* httpsHTTPS.wren */
 
var CURLOPT_URL = 10002
Line 1,008 ⟶ 1,027:
<br>
We now embed this in the following C program, compile and run it.
<syntaxhighlight lang="c">/* gcc httpsHTTPS.c -o httpsHTTPS -lcurl -lwren -lm */
 
#include <stdio.h>
Line 1,118 ⟶ 1,137:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "httpsHTTPS.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
9,482

edits