June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
27
Task/HTTPS-Authenticated/Haskell/https-authenticated.hs
Normal file
27
Task/HTTPS-Authenticated/Haskell/https-authenticated.hs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Main (main) where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.Default.Class (def)
|
||||
import Network.HTTP.Req
|
||||
( (/:)
|
||||
, GET(..)
|
||||
, NoReqBody(..)
|
||||
, basicAuth
|
||||
, https
|
||||
, jsonResponse
|
||||
, req
|
||||
, responseBody
|
||||
, runReq
|
||||
)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
response <- runReq def $ req
|
||||
GET
|
||||
(https "httpbin.org" /: "basic-auth" /: "someuser" /: "somepassword")
|
||||
NoReqBody
|
||||
jsonResponse
|
||||
(basicAuth "someuser" "somepassword")
|
||||
print (responseBody response :: Value)
|
||||
28
Task/HTTPS-Authenticated/Kotlin/https-authenticated.kotlin
Normal file
28
Task/HTTPS-Authenticated/Kotlin/https-authenticated.kotlin
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// version 1.2.0
|
||||
|
||||
import java.net.Authenticator
|
||||
import java.net.PasswordAuthentication
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
import java.net.URL
|
||||
import java.io.InputStreamReader
|
||||
import java.io.BufferedReader
|
||||
|
||||
object PasswordAuthenticator : Authenticator() {
|
||||
override fun getPasswordAuthentication() =
|
||||
PasswordAuthentication ("username", "password".toCharArray())
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val url = URL("https://somehost.com")
|
||||
val con = url.openConnection() as HttpsURLConnection
|
||||
Authenticator.setDefault(PasswordAuthenticator)
|
||||
con.allowUserInteraction = true
|
||||
con.connect()
|
||||
val isr = InputStreamReader(con.inputStream)
|
||||
val br = BufferedReader(isr)
|
||||
while (true) {
|
||||
val line = br.readLine()
|
||||
if (line == null) break
|
||||
println(line)
|
||||
}
|
||||
}
|
||||
10
Task/HTTPS-Authenticated/Perl-6/https-authenticated.pl6
Normal file
10
Task/HTTPS-Authenticated/Perl-6/https-authenticated.pl6
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
use HTTP::UserAgent;
|
||||
|
||||
my $username = 'username'; # my username
|
||||
my $password = 'password'; # my password
|
||||
my $address = 'http://192.168.1.1/Status_Router.asp'; # my local wireless router
|
||||
|
||||
my $ua = HTTP::UserAgent.new;
|
||||
$ua.auth( $username, $password );
|
||||
my $response = $ua.get: $address;
|
||||
say $response.is-success ?? $response.content !! $response.status-line;
|
||||
24
Task/HTTPS-Authenticated/Scala/https-authenticated.scala
Normal file
24
Task/HTTPS-Authenticated/Scala/https-authenticated.scala
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import java.net.{Authenticator, PasswordAuthentication, URL}
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
|
||||
import scala.io.BufferedSource
|
||||
|
||||
|
||||
object Authenticated extends App {
|
||||
|
||||
val con: HttpsURLConnection =
|
||||
new URL("https://somehost.com").openConnection().asInstanceOf[HttpsURLConnection]
|
||||
|
||||
object PasswordAuthenticator extends Authenticator {
|
||||
override def getPasswordAuthentication =
|
||||
new PasswordAuthentication("username", "password".toCharArray)
|
||||
}
|
||||
|
||||
Authenticator.setDefault(PasswordAuthenticator)
|
||||
con.setAllowUserInteraction(true)
|
||||
con.connect()
|
||||
|
||||
new BufferedSource(con.getInputStream).getLines.foreach(println(_))
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue