HTTPS: Difference between revisions

From Rosetta Code
Content added Content deleted
(Undo revision 124682 by 64.71.124.132 (talk): vandalism)
No edit summary
Line 7: Line 7:
=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
{{libheader|wininet}}
{{libheader|wininet}}
<lang AutoHotkey>URL := "https://sourceforge.net/"
<lang AutoHotkey>
URL := "https://sourceforge.net/"
WININET_Init()
WININET_Init()
msgbox % html := UrlGetContents(URL)
msgbox % html := UrlGetContents(URL)
Line 13: Line 14:
return
return
#include urlgetcontents.ahk
#include urlgetcontents.ahk
#include wininet.ahk</lang>
#include wininet.ahk
</lang>

=={{header|Batch File}}==
<lang batch>
curl.exe -k -s -L https://sourceforge.net/
</lang>

=={{header|C}}==
=={{header|C}}==
{{libheader|libcurl}}
{{libheader|libcurl}}
<lang c>#include <stdio.h>
<lang c>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <curl/curl.h>
Line 37: Line 46:
}
}
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}
}</lang>
</lang>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
{{works with|C sharp|3.0}}
{{works with|C sharp|3.0}}


<lang csharp>using System;
<lang csharp>
using System;
using System.Net;
using System.Net;


Line 54: Line 65:
Console.WriteLine(data);
Console.WriteLine(data);
}
}
}
}</lang>
</lang>


=={{header|Clojure}}==
=={{header|Clojure}}==

Using the duck-streams as a convenient wrapper for Java's networking classes, grabbing the contents of an HTTPS URL is as easy as:
Using the duck-streams as a convenient wrapper for Java's networking classes, grabbing the contents of an HTTPS URL is as easy as:


<lang clojure>(use '[clojure.contrib.duck-streams :only (slurp*)])
<lang clojure>
(use '[clojure.contrib.duck-streams :only (slurp*)])
(print (slurp* "https://sourceforge.net"))</lang>
(print (slurp* "https://sourceforge.net"))
</lang>


The usual Java mechanisms can be used to manage acceptance of SSL certificates if required.
The usual Java mechanisms can be used to manage acceptance of SSL certificates if required.


{{works with|Clojure|1.2}}
{{works with|Clojure|1.2}}
<lang clojure>(print (slurp "https://sourceforge.net"))</lang>
<lang clojure>
(print (slurp "https://sourceforge.net"))
</lang>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==

{{libheader|DRAKMA}}
{{libheader|DRAKMA}}


First grabbing the entire body as a string, and then by pulling from a stream. This is the same code as in [[HTTP Request]]; <code>drakma:http-request</code> supports SSL.
First grabbing the entire body as a string, and then by pulling from a stream. This is the same code as in [[HTTP Request]]; <code>drakma:http-request</code> supports SSL.


<lang lisp>
<lang lisp>(defun wget-drakma-string (url &optional (out *standard-output*))
(defun wget-drakma-string (url &optional (out *standard-output*))
"Grab the body as a string, and write it to out."
"Grab the body as a string, and write it to out."
(write-string (drakma:http-request url) out))
(write-string (drakma:http-request url) out))
Line 86: Line 101:


;; Use
;; Use
(wget-drakma-stream "https://sourceforge.net")</lang>
(wget-drakma-stream "https://sourceforge.net")
</lang>


=={{header|Delphi}}==
=={{header|Delphi}}==
{{libheader|OpenSSL}}
<lang Delphi>program ShowHTTPS;
<lang Delphi>
program ShowHTTPS;


{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
Line 111: Line 129:
lIOHandler.Free;
lIOHandler.Free;
end;
end;
end.</lang>
end.
</lang>


=={{header|Erlang}}==
=={{header|Erlang}}==
===Synchronous===
===Synchronous===
<lang erlang>-module(main).
<lang erlang>
-module(main).
-export([main/1]).
-export([main/1]).


Line 124: Line 144:
{ok, {_V, _H, Body}} -> io:fwrite("~p~n",[Body]);
{ok, {_V, _H, Body}} -> io:fwrite("~p~n",[Body]);
{error, Res} -> io:fwrite("~p~n", [Res])
{error, Res} -> io:fwrite("~p~n", [Res])
end.</lang>
end.
</lang>


===Asynchronous===
===Asynchronous===
<lang erlang>

<lang erlang>-module(main).
-module(main).
-export([main/1]).
-export([main/1]).


Line 139: Line 160:
_Any -> io:fwrite("Error: ~p~n",[_Any])
_Any -> io:fwrite("Error: ~p~n",[_Any])
after 10000 -> io:fwrite("Timed out.~n",[])
after 10000 -> io:fwrite("Timed out.~n",[])
end.</lang>
end.
</lang>


Using it
Using it
<lang erlang>|escript ./req.erl https://sourceforge.net/</lang>
<lang erlang>
|escript ./req.erl https://sourceforge.net/
</lang>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
The underlying .NET classes handle secure web connections the same way they manage insecure connections.
The underlying .NET classes handle secure web connections the same way they manage insecure connections.
<lang fsharp>#light
<lang fsharp>
#light
let wget (url : string) =
let wget (url : string) =
let c = new System.Net.WebClient()
let c = new System.Net.WebClient()
c.DownloadString(url)</lang>
c.DownloadString(url)
</lang>


=={{header|Groovy}}==
=={{header|Groovy}}==
<lang groovy>

<lang groovy>new URL("https://sourceforge.net").eachLine { println it }</lang>
new URL("https://sourceforge.net").eachLine { println it }
</lang>


=={{header|Ioke}}==
=={{header|Ioke}}==
{{trans|Java}}
{{trans|Java}}
<lang ioke>
<lang ioke>connection = URL new("https://sourceforge.net") openConnection
connection = URL new("https://sourceforge.net") openConnection
scanner = Scanner new(connection getInputStream)
scanner = Scanner new(connection getInputStream)


while(scanner hasNext,
while(scanner hasNext,
scanner next println
scanner next println
)
)</lang>
</lang>


=={{header|J}}==
=={{header|J}}==

Using <tt>gethttp</tt> from [[Web Scraping#J|Web Scraping]]
Using <tt>gethttp</tt> from [[Web Scraping#J|Web Scraping]]


<lang j>
<lang j> #page=: gethttp'https://sourceforge.net'
#page=: gethttp'https://sourceforge.net'
0
0
#page=: '--no-check-certificate' gethttp'https://sourceforge.net'
#page=: '--no-check-certificate' gethttp'https://sourceforge.net'
900</lang>
900
</lang>


(We can not load the example page using https unless we disable certificate checking. The numbers are the number of characters retrieved.)
(We can not load the example page using https unless we disable certificate checking. The numbers are the number of characters retrieved.)
Line 177: Line 207:
=={{header|Java}}==
=={{header|Java}}==
Additional certificate information is available through the [http://java.sun.com/javase/6/docs/api/javax/net/ssl/HttpsURLConnection.html javax.net.ssl.HttpsURLConnection] interface.
Additional certificate information is available through the [http://java.sun.com/javase/6/docs/api/javax/net/ssl/HttpsURLConnection.html javax.net.ssl.HttpsURLConnection] interface.
<lang Java>
<lang Java>URL url = new URL("https://sourceforge.net");
URL url = new URL("https://sourceforge.net");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
Scanner scanner = new Scanner(connection.getInputStream());
Scanner scanner = new Scanner(connection.getInputStream());
Line 183: Line 214:
while (scanner.hasNext()) {
while (scanner.hasNext()) {
System.out.println(scanner.next());
System.out.println(scanner.next());
}
}</lang>
</lang>


=={{header|Mathematica}}==
=={{header|Mathematica}}==
Straight forward "Import" task. More complicated secure web access can bee done using J/Link; essentially a link to Java API.
Straight forward "Import" task. More complicated secure web access can bee done using J/Link; essentially a link to Java API.
<lang Mathematica>content=Import["https://sourceforge.net", "HTML"]</lang>
<lang Mathematica>
content=Import["https://sourceforge.net", "HTML"]

</lang>


=={{header|Perl}}==
=={{header|Perl}}==
{{libheader|LWP}}
{{libheader|LWP}}
<lang perl>use strict;
<lang perl>
use strict;
use LWP::UserAgent;
use LWP::UserAgent;


Line 200: Line 234:
$response->is_success or die "Failed to GET '$url': ", $response->status_line;
$response->is_success or die "Failed to GET '$url': ", $response->status_line;


print $response->as_string;</lang>
print $response->as_string;
</lang>


=={{header|PHP}}==
=={{header|PHP}}==
<lang php>
<lang php>echo file_get_contents('https://sourceforge.net');</lang>
echo file_get_contents('https://sourceforge.net');
</lang>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
PicoLisp has no functionality for communicating with a HTTPS server
PicoLisp has no functionality for communicating with a HTTPS server
(only for the other direction), but it is easy to use an external tool
(only for the other direction), but it is easy to use an external tool
<lang PicoLisp>
<lang PicoLisp>(in '(curl "https://sourceforge.net") # Open a pipe to 'curl'
(in '(curl "https://sourceforge.net") # Open a pipe to 'curl'
(out NIL (echo)) ) # Echo to standard output</lang>
(out NIL (echo)) ) # Echo to standard output
</lang>


=={{header|Pike}}==
=={{header|Pike}}==
<lang pike>int main() {
<lang pike>
int main() {
write("%s\n", Protocols.HTTP.get_url_data("https://sourceforge.net"));
write("%s\n", Protocols.HTTP.get_url_data("https://sourceforge.net"));
}
}</lang>
</lang>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang powershell>$wc = New-Object Net.WebClient
<lang powershell>
$wc = New-Object Net.WebClient
$wc.DownloadString('https://sourceforge.net')</lang>
$wc.DownloadString('https://sourceforge.net')
</lang>

If the certificate could not be validated (untrusted, self-signed, expired), then an Exception is thrown with the message ''“The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.”'' so certificate validation is done automatically by the method.
If the certificate could not be validated (untrusted, self-signed, expired), then an Exception is thrown with the message ''“The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.”'' so certificate validation is done automatically by the method.


Line 227: Line 271:
<lang Python>
<lang Python>
from urllib.request import urlopen
from urllib.request import urlopen
print(urlopen('https://sourceforge.net/').read())</lang>
print(urlopen('https://sourceforge.net/').read())
</lang>


(Python 2.x)
(Python 2.x)
<lang Python>
<lang Python>
from urllib2 import urlopen
from urllib2 import urlopen
print urlopen('https://sourceforge.net/').read()</lang>
print urlopen('https://sourceforge.net/').read()
</lang>


=={{header|R}}==
=={{header|R}}==
{{libheader|RCurl}}
{{libheader|RCurl}}

{{libheader|XML}}
{{libheader|XML}}


Line 243: Line 288:
webpage <- getURL("https://sourceforge.net/", .opts=list(followlocation=TRUE, ssl.verifyhost=FALSE, ssl.verifypeer=FALSE))</lang>
webpage <- getURL("https://sourceforge.net/", .opts=list(followlocation=TRUE, ssl.verifyhost=FALSE, ssl.verifypeer=FALSE))</lang>
In this case, the webpage output contains unprocessed characters, e.g. \" instead of " and \\ instead of \, so we need to process the markup.
In this case, the webpage output contains unprocessed characters, e.g. \" instead of " and \\ instead of \, so we need to process the markup.

<lang R>wp <- readLines(tc <- textConnection(webpage))
close(tc)</lang>
<lang R>
wp <- readLines(tc <- textConnection(webpage))
close(tc)
</lang>

Finally, we parse the HTML and find the interesting bit.
Finally, we parse the HTML and find the interesting bit.
<lang R>pagetree <- htmlTreeParse(wp)
pagetree$children$html</lang>


<lang R>
pagetree <- htmlTreeParse(wp)
pagetree$children$html
</lang>


=={{header|REALbasic}}==
=={{header|REALbasic}}==
REALBasic provides an HTTPSecureSocket class for handling HTTPS connections. The 'Get' method of the HTTPSecureSocket class does not return any data (it can write data out to a file, but I chose not to take that route.) So, this example instead uses a subclass of the HTTPSecureSocket class which adds the necessary functionality to allow us to merely call a method of the HTTPSecureSocket which accepts a URL and returns a string containing the retrieved data. (There is undoubtedly a cleaner, nicer way to do this.) Note that in this example I declare classes in code (using Class/End Class,) whereas in real life classes are declared using the IDE.
REALBasic provides an HTTPSecureSocket class for handling HTTPS connections. The 'Get' method of the HTTPSecureSocket class does not return any data (it can write data out to a file, but I chose not to take that route.) So, this example instead uses a subclass of the HTTPSecureSocket class which adds the necessary functionality to allow us to merely call a method of the HTTPSecureSocket which accepts a URL and returns a string containing the retrieved data. (There is undoubtedly a cleaner, nicer way to do this.) Note that in this example I declare classes in code (using Class/End Class,) whereas in real life classes are declared using the IDE.

<lang REALbasic>
<lang REALbasic>
Class App As ConsoleApplication
Class App As ConsoleApplication
Line 281: Line 333:
=={{header|Ruby}}==
=={{header|Ruby}}==
This solution doesn't use the <code>open-uri</code> convenience package that the [[HTTP Request#Ruby]] solution uses: the <code>Net::HTTP</code> object must be told to use SSL before the session is started.
This solution doesn't use the <code>open-uri</code> convenience package that the [[HTTP Request#Ruby]] solution uses: the <code>Net::HTTP</code> object must be told to use SSL before the session is started.

<lang ruby>require 'net/https'
<lang ruby>
require 'net/https'
require 'uri'
require 'uri'
require 'pp'
require 'pp'
Line 295: Line 349:
pp content.to_hash
pp content.to_hash
puts content.body
puts content.body
end</lang>
end
</lang>


outputs
outputs
<pre>["302", "Found"]
<pre>
["302", "Found"]
{"location"=>["http://sourceforge.net/"],
{"location"=>["http://sourceforge.net/"],
"content-type"=>["text/html; charset=UTF-8"],
"content-type"=>["text/html; charset=UTF-8"],
Line 318: Line 374:


</body>
</body>
</html></pre>
</html>
</pre>


=={{header|Tcl}}==
=={{header|Tcl}}==
Though Tcl's built-in <code>http</code> package does not understand SSL, it does support the registration of external handlers to accommodate additional protocols. This allows the use of the [http://tls.sourceforge.net/ Tls] package to supply the missing functionality with only a single line to complete the registration.
Though Tcl's built-in <code>http</code> package does not understand SSL, it does support the registration of external handlers to accommodate additional protocols. This allows the use of the [http://tls.sourceforge.net/ Tls] package to supply the missing functionality with only a single line to complete the registration.

<lang tcl>package require http
<lang tcl>
package require http
package require tls
package require tls


Line 337: Line 396:
# Now as for conventional use of the “http” package
# Now as for conventional use of the “http” package
puts [http::data $token]
puts [http::data $token]
http::cleanup $token</lang>
http::cleanup $token
</lang>

=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<lang tuscript>
<lang tuscript>
Line 343: Line 404:
SET DATEN = REQUEST ("https://sourceforge.net")
SET DATEN = REQUEST ("https://sourceforge.net")
*{daten}
*{daten}
</lang>

=={{header|UNIX Shell}}==
<lang bash>
curl -k -s -L https://sourceforge.net/
</lang>

=={{header|VBScript}}==
{{Libheader|Microsoft.XmlHTTP}}

Based on code at [http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/how-to-retrieve-html-web-pages-with-vbscript-via-the-microsoftxmlhttp-object/ How to retrieve HTML web pages with VBScript via the Microsoft.XmlHttp object]
<lang vb>
Option Explicit

Const sURL="https://sourceforge.net/"

Dim oHTTP
Set oHTTP = CreateObject("Microsoft.XmlHTTP")

On Error Resume Next
oHTTP.Open "GET", sURL, False
oHTTP.Send ""
If Err.Number = 0 Then
WScript.Echo oHTTP.responseText
Else
Wscript.Echo "error " & Err.Number & ": " & Err.Description
End If

Set oHTTP = Nothing
</lang>

=={{header|Visual Basic .NET}}==
<lang vbnet>
Imports System.Net

Dim client As WebClient = New WebClient()
Dim content As String = client.DownloadString("https://sourceforge.net")
Console.WriteLine(content)
</lang>
</lang>


{{omit from|Applesoft BASIC|No TCP/IP network support on Apple II}}
{{omit from|Applesoft BASIC|No TCP/IP network support on Apple II}}
{{omit from|Batch File|Does not have network access.}}
{{omit from|Brainf***}}
{{omit from|Brainf***}}
{{omit from|Inform 7|Does not have network access.}}
{{omit from|Inform 7|Does not have network access.}}

Revision as of 02:13, 1 December 2011

Task
HTTPS
You are encouraged to solve this task according to the task description, using any language you may know.

Print an HTTPS URL's content to the console. Checking the host certificate for validity is recommended. The client should not authenticate itself to the server — the webpage https://sourceforge.net/ supports that access policy — as that is the subject of other tasks.

Readers may wish to contrast with the HTTP Request task, and also the task on HTTPS request with authentication.

AutoHotkey

Library: wininet

<lang AutoHotkey> URL  := "https://sourceforge.net/" WININET_Init() msgbox % html := UrlGetContents(URL) WININET_UnInit() return

  1. include urlgetcontents.ahk
  2. include wininet.ahk

</lang>

Batch File

<lang batch> curl.exe -k -s -L https://sourceforge.net/ </lang>

C

Library: libcurl

<lang c>

  1. include <stdio.h>
  2. include <stdlib.h>
  3. include <curl/curl.h>

int main(void) {

       CURL *curl;
       char buffer[CURL_ERROR_SIZE];
       if ((curl = curl_easy_init()) != NULL) {
               curl_easy_setopt(curl, CURLOPT_URL, "https://sourceforge.net/");
               curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
               curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, buffer);
               if (curl_easy_perform(curl) != CURLE_OK) {
                       fprintf(stderr, "%s\n", buffer);
                       return EXIT_FAILURE;
               }
               curl_easy_cleanup(curl);
       }
       return EXIT_SUCCESS;

} </lang>

C#

Works with: C sharp version 3.0

<lang csharp> using System; using System.Net;

class Program {

   static void Main(string[] args)
   {
       var client = new WebClient();
       var data = client.DownloadString("https://www.google.com");
       Console.WriteLine(data);
   }

} </lang>

Clojure

Using the duck-streams as a convenient wrapper for Java's networking classes, grabbing the contents of an HTTPS URL is as easy as:

<lang clojure> (use '[clojure.contrib.duck-streams :only (slurp*)]) (print (slurp* "https://sourceforge.net")) </lang>

The usual Java mechanisms can be used to manage acceptance of SSL certificates if required.

Works with: Clojure version 1.2

<lang clojure> (print (slurp "https://sourceforge.net")) </lang>

Common Lisp

Library: DRAKMA

First grabbing the entire body as a string, and then by pulling from a stream. This is the same code as in HTTP Request; drakma:http-request supports SSL.

<lang lisp> (defun wget-drakma-string (url &optional (out *standard-output*))

 "Grab the body as a string, and write it to out."
 (write-string (drakma:http-request url) out))

(defun wget-drakma-stream (url &optional (out *standard-output*))

 "Grab the body as a stream, and write it to out."
 (loop with body = (drakma:http-request url :want-stream t)
       for line = (read-line body nil nil)
       while line do (write-line line)
       finally (close body)))
Use

(wget-drakma-stream "https://sourceforge.net") </lang>

Delphi

Library: OpenSSL

<lang Delphi> program ShowHTTPS;

{$APPTYPE CONSOLE}

uses IdHttp, IdSSLOpenSSL;

var

 s: string;
 lHTTP: TIdHTTP;
 lIOHandler: TIdSSLIOHandlerSocketOpenSSL;

begin

 lHTTP := TIdHTTP.Create(nil);
 lIOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
 try
   lHTTP.IOHandler := lIOHandler;
   lHTTP.HandleRedirects := True;
   s := lHTTP.Get('https://sourceforge.net/');
   Writeln(s);
 finally
   lHTTP.Free;
   lIOHandler.Free;
 end;

end. </lang>

Erlang

Synchronous

<lang erlang> -module(main). -export([main/1]).

main([Url|[]]) ->

  inets:start(),
  ssl:start(),
  case http:request(get, {URL, []}, [{ssl,[{verify,0}]}], []) of
      {ok, {_V, _H, Body}} -> io:fwrite("~p~n",[Body]);
      {error, Res} -> io:fwrite("~p~n", [Res])
  end.

</lang>

Asynchronous

<lang erlang> -module(main). -export([main/1]).

main([Url|[]]) ->

  inets:start(),
  ssl:start(),
  http:request(get, {Url, [] }, [{ssl,[{verify,0}]}], [{sync, false}]),
  receive
      {http, {_ReqId, Res}} -> io:fwrite("~p~n",[Res]);
      _Any -> io:fwrite("Error: ~p~n",[_Any])
      after 10000 -> io:fwrite("Timed out.~n",[])
  end.

</lang>

Using it <lang erlang> |escript ./req.erl https://sourceforge.net/ </lang>

F#

The underlying .NET classes handle secure web connections the same way they manage insecure connections. <lang fsharp>

  1. light

let wget (url : string) =

   let c = new System.Net.WebClient()
   c.DownloadString(url)

</lang>

Groovy

<lang groovy> new URL("https://sourceforge.net").eachLine { println it } </lang>

Ioke

Translation of: Java

<lang ioke> connection = URL new("https://sourceforge.net") openConnection scanner = Scanner new(connection getInputStream)

while(scanner hasNext,

 scanner next println

) </lang>

J

Using gethttp from Web Scraping

<lang j>

  #page=: gethttp'https://sourceforge.net'

0

  #page=: '--no-check-certificate' gethttp'https://sourceforge.net'

900 </lang>

(We can not load the example page using https unless we disable certificate checking. The numbers are the number of characters retrieved.)

Java

Additional certificate information is available through the javax.net.ssl.HttpsURLConnection interface. <lang Java> URL url = new URL("https://sourceforge.net"); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); Scanner scanner = new Scanner(connection.getInputStream());

while (scanner.hasNext()) {

   System.out.println(scanner.next());

} </lang>

Mathematica

Straight forward "Import" task. More complicated secure web access can bee done using J/Link; essentially a link to Java API. <lang Mathematica> content=Import["https://sourceforge.net", "HTML"] </lang>

Perl

Library: LWP

<lang perl> use strict; use LWP::UserAgent;

my $url = 'https://www.rosettacode.org'; my $response = LWP::UserAgent->new->get( $url );

$response->is_success or die "Failed to GET '$url': ", $response->status_line;

print $response->as_string; </lang>

PHP

<lang php> echo file_get_contents('https://sourceforge.net'); </lang>

PicoLisp

PicoLisp has no functionality for communicating with a HTTPS server (only for the other direction), but it is easy to use an external tool <lang PicoLisp> (in '(curl "https://sourceforge.net") # Open a pipe to 'curl'

  (out NIL (echo)) )                  # Echo to standard output

</lang>

Pike

<lang pike> int main() {

   write("%s\n", Protocols.HTTP.get_url_data("https://sourceforge.net"));

} </lang>

PowerShell

<lang powershell> $wc = New-Object Net.WebClient $wc.DownloadString('https://sourceforge.net') </lang>

If the certificate could not be validated (untrusted, self-signed, expired), then an Exception is thrown with the message “The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.” so certificate validation is done automatically by the method.

Python

Python's urllib.request library, (urllib2 in Python2.x) has support for SSL if the interpreter's underlying httplib libraries were compiled with SSL support. By default this will be the enabled for default Python installations on most platforms.

Python 3.x: <lang Python> from urllib.request import urlopen print(urlopen('https://sourceforge.net/').read()) </lang>

(Python 2.x) <lang Python> from urllib2 import urlopen print urlopen('https://sourceforge.net/').read() </lang>

R

Library: RCurl
Library: XML

The basic idea is to use getURL (as with HTTP_Request), but with some extra parameters. <lang R>library(RCurl) webpage <- getURL("https://sourceforge.net/", .opts=list(followlocation=TRUE, ssl.verifyhost=FALSE, ssl.verifypeer=FALSE))</lang> In this case, the webpage output contains unprocessed characters, e.g. \" instead of " and \\ instead of \, so we need to process the markup.

<lang R> wp <- readLines(tc <- textConnection(webpage)) close(tc) </lang>

Finally, we parse the HTML and find the interesting bit.

<lang R> pagetree <- htmlTreeParse(wp) pagetree$children$html </lang>

REALbasic

REALBasic provides an HTTPSecureSocket class for handling HTTPS connections. The 'Get' method of the HTTPSecureSocket class does not return any data (it can write data out to a file, but I chose not to take that route.) So, this example instead uses a subclass of the HTTPSecureSocket class which adds the necessary functionality to allow us to merely call a method of the HTTPSecureSocket which accepts a URL and returns a string containing the retrieved data. (There is undoubtedly a cleaner, nicer way to do this.) Note that in this example I declare classes in code (using Class/End Class,) whereas in real life classes are declared using the IDE.

<lang REALbasic> Class App As ConsoleApplication

   Function Run(args() as String) As Integer
     Dim sock As New secureSock  //Subclassed from the HTTPSecureSocket class
     Stdout.Write(sock.Getter("https://sourceforge.net"))
   End Function

End Class

Class secureSock As HTTPSecureSocket

   Private pageData As String
   Sub PageReceived(url as string, httpStatus as integer, headers as internetHeaders, content as string)
     pageData = content
   End Sub
   Function getter(URL As String) As String
     me.Get(URL)
     Return pageData
   End Function

End Class </lang>


RLaB

See [[1]]

Ruby

This solution doesn't use the open-uri convenience package that the HTTP Request#Ruby solution uses: the Net::HTTP object must be told to use SSL before the session is started.

<lang ruby> require 'net/https' require 'uri' require 'pp'

uri = URI.parse('https://sourceforge.net') http = Net::HTTP.new(uri.host,uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE

http.start do

 content = http.get("/")
 p [content.code, content.message]
 pp content.to_hash
 puts content.body

end </lang>

outputs

["302", "Found"]
{"location"=>["http://sourceforge.net/"],
 "content-type"=>["text/html; charset=UTF-8"],
 "connection"=>["close"],
 "server"=>["nginx/0.7.60"],
 "date"=>["Sun, 30 Aug 2009 20:20:07 GMT"],
 "content-length"=>["229"],
 "set-cookie"=>
  ["sf.consume=89f65c6fadd222338b2f3de6f8e8a17b2c8f67c2gAJ9cQEoVQhfZXhwaXJlc3ECY2RhdGV0aW1lCmRhdGV0aW1lCnEDVQoH9gETAw4HAAAAhVJxBFUDX2lkcQVVIDEyOWI2MmVkOWMwMWYxYWZiYzE5Y2JhYzcwZDMxYTE4cQZVDl9hY2Nlc3NlZF90aW1lcQdHQdKmt73UN21VDl9jcmVhdGlvbl90aW1lcQhHQdKmt73UN2V1Lg==; expires=Tue, 19-Jan-2038 03:14:07 GMT; Path=/"]}
<html>
 <head>
  <title>302 Found</title>
 </head>
 <body>
  <h1>302 Found</h1>
  The resource was found at <a href="http://sourceforge.net/">http://sourceforge.net/</a>;
you should be redirected automatically.


 </body>
</html>

Tcl

Though Tcl's built-in http package does not understand SSL, it does support the registration of external handlers to accommodate additional protocols. This allows the use of the Tls package to supply the missing functionality with only a single line to complete the registration.

<lang tcl> package require http package require tls

  1. Tell the http package what to do with “https:” URLs.
  2. First argument is the protocol name, second the default port, and
  3. third the connection builder command

http::register "https" 443 ::tls::socket

  1. Make a secure connection, which is almost identical to normal
  2. connections except for the different protocol in the URL.

set token [http::geturl "https://sourceforge.net/"]

  1. Now as for conventional use of the “http” package

puts [http::data $token] http::cleanup $token </lang>

TUSCRIPT

<lang tuscript> $$ MODE TUSCRIPT SET DATEN = REQUEST ("https://sourceforge.net")

  • {daten}

</lang>

UNIX Shell

<lang bash> curl -k -s -L https://sourceforge.net/ </lang>

VBScript

Based on code at How to retrieve HTML web pages with VBScript via the Microsoft.XmlHttp object <lang vb> Option Explicit

Const sURL="https://sourceforge.net/"

Dim oHTTP Set oHTTP = CreateObject("Microsoft.XmlHTTP")

On Error Resume Next oHTTP.Open "GET", sURL, False oHTTP.Send "" If Err.Number = 0 Then

    WScript.Echo oHTTP.responseText

Else

    Wscript.Echo "error " & Err.Number & ": " & Err.Description

End If

Set oHTTP = Nothing </lang>

Visual Basic .NET

<lang vbnet> Imports System.Net

Dim client As WebClient = New WebClient() Dim content As String = client.DownloadString("https://sourceforge.net") Console.WriteLine(content) </lang>