HTTPS/Authenticated: Difference between revisions
< HTTPS
Content added Content deleted
(link into the chain of HTTPS-related tasks) |
m (→{{header|Tcl}}: link to tcllib category) |
||
Line 57: | Line 57: | ||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
{{works with|Tcl|8.6}} for the <code>binary encode</code> subcommand, otherwise use the <code>base64</code> package from |
{{works with|Tcl|8.6}} for the <code>binary encode</code> subcommand, otherwise use the <code>base64</code> package from {{libheader|tcllib}} |
||
Uses the [http://tls.sourceforge.net Tls] package. |
Uses the [http://tls.sourceforge.net Tls] package. |
Revision as of 11:12, 1 June 2009
HTTPS/Authenticated
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
The goal of this task is to demonstrate HTTPS requests with authentication. Implementations of this task should not use client certificates for this: that is the subject of another task.
Perl
use LWP::UserAgent qw(); my $ua = LWP::UserAgent->new; my $netloc = 'http://www.buddhism-dict.net/cgi-bin/xpr-dealt.pl:80'; $ua->credentials( $netloc, 'CJK-E and Buddhist Dictionaries', # basic realm 'guest', # user '', # empty pw ); my $response = $ua->get($netloc);
use WWW::Mechanize qw(); my $mech = WWW::Mechanize->new; $mech->get('https://login.yahoo.com/'); $mech->submit_form(with_fields => { login => 'XXXXXX', passwd => 'YYYYYY', '.persistent' => 'y', # tick checkbox });
Python
Note: You should install mechanize to run code below. Visit: http://wwwsearch.sourceforge.net/mechanize/
#!/usr/bin/python # -*- coding: utf-8 -*- from mechanize import Browser USER_AGENT = "Mozilla/5.0 (X11; U; Linux i686; tr-TR; rv:1.8.1.9) Gecko/20071102 Pardus/2007 Firefox/2.0.0.9" br = Browser() br.addheaders = [("User-agent", USER_AGENT)] # remove comment if you get debug output # br.set_debug_redirects(True) # br.set_debug_responses(True) # br.set_debug_http(True) br.open("https://www.facebook.com") br.select_form("loginform") br['email'] = "xxxxxxx@xxxxx.com" br['pass'] = "xxxxxxxxx" br['persistent'] = ["1"] response = br.submit() print response.read()
Tcl
for the binary encode
subcommand, otherwise use the base64
package from
Uses the Tls package. <lang Tcl>package require http package require tls http::register https 443 ::tls::socket
- Generate the authentication
set user theUser set pass thePassword dict set auth Authenticate "Basic [binary encode base64 ${user}:${pass}]"
- Make a secure authenticated connection
set token [http::geturl https://secure.example.com/ -headers $auth]
- Now as for conventional use of the “http” package
set data [http::data $token] http::cleanup $token</lang>