HTTPS/Authenticated: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|Phix}}: added syntax colouring, marked p2js incompatible) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 7:
{{libheader|iweb}}
{{libheader|COM}}
<
pwb := iWeb_newGui(0, 0, 1000, 800)
iWeb_nav(pwb, "http://www.facebook.com/login.php?ref=pf")
Line 21:
#Include iweb.ahk
#Include COM.ahk
#Include COMinvokeDeep.ahk</
=={{header|BaCon}}==
<
website$ = "website.com"
Line 40:
CLOSE NETWORK conn
PRINT total$</
=={{header|C}}==
{{libheader|libcurl}}
<
#include <stdlib.h>
#include "curl/curl.h"
Line 65:
}
return EXIT_SUCCESS;
}</
=={{header|C sharp|C#}}==
{{works with|C sharp|3.0}}
<
using System;
using System.Net;
Line 90:
}
}
</syntaxhighlight>
=={{header|Clojure}}==
{{libheader|clj-http}}
<
{:basic-auth ["user" "pass"]})</
=={{header|Delphi}}==
<
{$APPTYPE CONSOLE}
Line 124:
lIOHandler.Free;
end;
end.</
=={{header|Go}}==
The task solution is really the client program, but to test it I wrote a server and created a custom certificate. I won't describe the certificate, but this is the server:
<
import (
Line 165:
http.HandleFunc("/", hw)
log.Fatal(http.ListenAndServeTLS(":8080", "cert.pem", "key.pem", nil))
}</
It is a "Hello world" server, but over TLS and with basic authentication required on the Get. Errors are logged to aid client debugging.
The client:
<
import (
Line 217:
}
fmt.Println(string(b))
}</
=={{header|Haskell}}==
Line 223:
Example uses the [https://hackage.haskell.org/package/req <tt>req</tt>] and [https://hackage.haskell.org/package/aeson <tt>aeson</tt>] packages:
<
module Main (main) where
Line 249:
jsonResponse
(basicAuth "someuser" "somepassword")
print (responseBody response :: Value)</
=={{header|Julia}}==
An example using HTTP (see the source for HTTP.jl for the code below ) to access and play a song:
<syntaxhighlight lang="julia">
using HTTP, HTTP.IOExtras, JSON, MusicProcessing
HTTP.open("POST", "http://music.com/play") do io
Line 267:
end
end
</syntaxhighlight>
=={{header|Kotlin}}==
<
import java.net.Authenticator
Line 297:
println(line)
}
}</
=={{header|Lasso}}==
<
local(x = curl('https://sourceforge.net'))
#x->set(CURLOPT_USERPWD, #username + ':' + #password)
local(y = #x->result)
#y->asString</
=={{header|LiveCode}}==
HTTP Basic Auth as part of url
<
libURLFollowHttpRedirects true
libURLSetSSLVerification true
put URL "https://user:passwd@example.basicauth.com/" into response
put response
end getAuthWebResource</
You can also set the headers for the basic auth requests
<
libURLFollowHttpRedirects true
libURLSetSSLVerification true
Line 322:
put URL "https://example.basicauth.com" into response
put response
end getAuthWebResource</
=={{header|Lua}}==
Line 328:
{{libheader|lua-requests}}
<
local requests = require('requests')
local auth = requests.HTTPBasicAuth('admin', 'admin')
Line 336:
})
io.write(string.format('Status: %d', resp.status_code))
</syntaxhighlight>
{{out}}
Line 346:
{{libheader|OpenSSL}}
<
const
Line 354:
let headers = newHttpHeaders({"Authorization": "Basic " & base64.encode(User & ":" & Password)})
let client = newHttpClient(headers = headers)
echo client.getContent("https://httpbin.org/basic-auth/admin/admin")</
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
For[ i=0, i < Length[a] , i++, SomeFunction[a]]</
=={{header|Perl}}==
{{libheader|LWP}}
<
my $ua = LWP::UserAgent->new;
my $netloc = 'http://www.buddhism-dict.net/cgi-bin/xpr-dealt.pl:80';
Line 380:
passwd => 'YYYYYY',
'.persistent' => 'y', # tick checkbox
});</
=={{header|Phix}}==
Line 386:
Exactly the same as the [[HTTP#Phix]] task.
You can of course use curl_easy_setopt(curl,CURLOPT_USERPWD,"user:password") rather than embed that in the url.
<!--<
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">libcurl</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 397:
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span>
<!--</
=={{header|PicoLisp}}==
<
(in (list 'curl "-u" (pack User ': Pass) Url)
(while (line)
(doSomeProcessingWithLine @) ) ) )</
=={{header|PowerShell}}==
{{trans|C#}}
<
# credentials of current user:
$client.Credentials = [Net.CredentialCache]::DefaultCredentials
Line 412:
# $client.Credentials = [System.Net.NetworkCredential]::new("User", "Password")
$data = $client.DownloadString("https://example.com")
Write-Host $data</
=={{header|Python}}==
{{works with|Python|2.4 and 2.6}}
Line 418:
'''Note:''' You should install '''''mechanize''''' to run code below. Visit: http://wwwsearch.sourceforge.net/mechanize/
<
# -*- coding: utf-8 -*-
Line 441:
response = br.submit()
print response.read()</
{{libheader|Requests}}
{{works with|Python|2.7, 3.4–3.7}}
<
username = "user"
Line 453:
response = requests.get(url, auth=(username, password)
print(response.text)</
=={{header|Racket}}==
<
#lang racket
Line 477:
(for ([l (in-port read-line (get-pure-port (string->url "https://www.google.com/")))])
(displayln l))))
</syntaxhighlight>
=={{header|Raku}}==
Line 484:
Used here to connect to my local wireless router to a page that is password protected. Obviously not going to be generally publicly accessible but should be easily adaptable to other sites / devices.
<syntaxhighlight lang="raku"
my $username = 'username'; # my username
Line 493:
$ua.auth( $username, $password );
my $response = $ua.get: $address;
say $response.is-success ?? $response.content !! $response.status-line;</
=={{header|Ruby}}==
<
require 'net/http'
Line 504:
request.basic_auth('username', 'password')
http.request request
end</
=={{header|Run BASIC}}==
<
<CENTER><TABLE CELLPADDING=0 CELLSPACING=0 border=1 bgcolor=wheat>
<TR><TD colspan=2 bgcolor=tan align=center>LOGIN</TD></TR>
Line 538:
[exit]
end</
[[File:ClientAuthorizationRunBasic.png]]
=={{header|Rust}}==
<
extern crate reqwest;
Line 563:
println!("{}", body);
}
</syntaxhighlight>
{{out}}
<pre>
Line 570:
=={{header|Scala}}==
<
import javax.net.ssl.HttpsURLConnection
Line 593:
new BufferedSource(con.getInputStream).getLines.foreach(println(_))
}</
=={{header|Sidef}}==
<
var mech = %s'WWW::Mechanize'.new(
Line 609:
'login' => 'XXXXXX',
'passwd' => 'YYYYYY',
))</
=={{header|Tcl}}==
Line 615:
{{tcllib|base64}}
Uses the [http://tls.sourceforge.net Tls] package.
<
package require tls
http::register https 443 ::tls::socket
Line 629:
# Now as for conventional use of the “http” package
set data [http::data $token]
http::cleanup $token</
=={{header|Visual Basic}}==
Line 638:
{{works with|VBA|6.5}}
{{works with|VBA|7.1}}
<
' in the "references" dialog of the IDE, check
' "Microsoft WinHTTP Services, version 5.1" (winhttp.dll)
Line 659:
HttpReq.Send
Debug.Print HttpReq.ResponseText
End Sub</
=={{header|Wren}}==
Line 665:
{{libheader|libcurl}}
An embedded program so we can ask the C host to communicate with libcurl for us.
<
var CURLOPT_URL = 10002
Line 695:
return
}
curl.easyCleanup()</
<br>
We now embed this in the following C program, compile and run it.
<
#include <stdio.h>
Line 824:
free(script);
return 0;
}</
=={{header|zkl}}==
Using cURL to do the heavy lifting, get a XML list of computers connected to my router.
<
zkl: var data=ZC().get("http://usr:pw@192.168.1.1/computer_list.xml")
L(Data(1,049),121,0)
zkl: data[0][121,*].text</
{{out}}
<pre>
|