HTTPS/Authenticated: Difference between revisions

m
→‎{{header|Wren}}: Another minor change
m (Added command to compile the example (need option -d:ssl).)
m (→‎{{header|Wren}}: Another minor change)
 
(4 intermediate revisions by 3 users not shown)
Line 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 384 ⟶ 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}}==
Line 399 ⟶ 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 709 ⟶ 756:
{{libheader|libcurl}}
An embedded program so we can ask the C host to communicate with libcurl for us.
<syntaxhighlight lang="ecmascriptwren">/* https_authenticatedHTTPS_Authenticated.wren */
 
var CURLOPT_URL = 10002
Line 742 ⟶ 789:
<br>
We now embed this in the following C program, compile and run it.
<syntaxhighlight lang="c">/* gcc https_authenticatedHTTPS_Authenticated.c -o https_authenticatedHTTPS_Authenticated -lcurl -lwren -lm */
 
#include <stdio.h>
Line 852 ⟶ 899:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "https_authenticatedHTTPS_Authenticated.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
9,476

edits