HTTPS/Authenticated: Difference between revisions
m
→{{header|Wren}}: Another minor change
Jazzedpineda (talk | contribs) (Omitted EasyLang) |
m (→{{header|Wren}}: Another minor change) |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 3:
The goal of this task is to demonstrate [[HTTPS request]]s with authentication.
Implementations of this task should not use client certificates for this: that is the subject of [[Client-Authenticated HTTPS Request|another task]].
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">user: "admin"
pass: "admin"
inspect request.headers:#[
Authorization: "Basic " ++ encode user ++ ":" ++ pass
] "https://httpbin.org/basic-auth/admin/admin" ø</syntaxhighlight>
{{out}}
<pre>[ :dictionary
version : 1.1 :string
body : {
"authenticated": true,
"user": "admin"
}
:string
headers : [ :dictionary
server : gunicorn/19.9.0 :string
content-length : 48 :integer
access-control-allow-credentials : true :logical
content-type : application/json :string
date : [ :date
hour : 15 :integer
minute : 14 :integer
second : 57 :integer
nanosecond : 0 :integer
day : 20 :integer
Day : Tuesday :string
days : 353 :integer
month : 12 :integer
Month : December :string
year : 2022 :integer
utc : -3600 :integer
]
access-control-allow-origin : * :string
connection : keep-alive :string
]
status : 200 :integer
]</pre>
=={{header|AutoHotkey}}==
Line 250 ⟶ 292:
(basicAuth "someuser" "somepassword")
print (responseBody response :: Value)</syntaxhighlight>
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.io.IOException;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
public final class HTTPSAuthenticated {
public static void main(String[] aArgs) throws IOException, InterruptedException, URISyntaxException {
HttpClient client = HttpClient.newBuilder()
.authenticator( new MyAuthenticator() )
.build();
HttpRequest request = HttpRequest.newBuilder()
.GET()
.uri( new URI("https://postman-echo.com/basic-auth") ) // This website requires authentication
.build();
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
System.out.println("Status: " + response.statusCode());
}
}
final class MyAuthenticator extends Authenticator {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
String username = "kingkong";
String password = "test1234";
return new PasswordAuthentication(username, password.toCharArray());
}
}
</syntaxhighlight>
{{ out }}
<pre>
Status: 200
</pre>
=={{header|Julia}}==
Line 342 ⟶ 431:
Status: 200
</pre>
=={{header|Mathematica}} / {{header|Wolfram Language}}==▼
<syntaxhighlight lang="mathematica">a = RunThrough["curl -u JohnDoe:Password https://www.example.com", 1]▼
For[ i=0, i < Length[a] , i++, SomeFunction[a]]</syntaxhighlight>▼
=={{header|Nim}}==
{{libheader|OpenSSL}}
Compile with command <code>nim c -d:ssl https_authenticated.nim</code>.
<syntaxhighlight lang="nim">import httpclient, base64
Line 355 ⟶ 450:
let client = newHttpClient(headers = headers)
echo client.getContent("https://httpbin.org/basic-auth/admin/admin")</syntaxhighlight>
▲=={{header|Mathematica}} / {{header|Wolfram Language}}==
▲<syntaxhighlight lang="mathematica">a = RunThrough["curl -u JohnDoe:Password https://www.example.com", 1]
▲For[ i=0, i < Length[a] , i++, SomeFunction[a]]</syntaxhighlight>
=={{header|Perl}}==
Line 665 ⟶ 756:
{{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 698 ⟶ 789:
<br>
We now embed this in the following C program, compile and run it.
<syntaxhighlight lang="c">/* gcc
#include <stdio.h>
Line 808 ⟶ 899:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
|