NAME

HTTPSClient - HTTPS Client to connect to a HTTPS-Server and execute POST- and GET- methods.

SYNOPSIS

use HTTPSClient;

# instantiate
my $c=HTTPSClient->new (Host=>"localhost:2000",
                        SSL_verifycn_name => "server.domain.name.no",
                        SSL_verifycn_scheme => "https",
                        SSL_key_file => "./private.key",
                        SSL_cert_file => "./public.key",
                        SSL_ca_file => "./DigiCertCA.crt",
                       );

# attempt connect
if (!$c->connect()) {
   print "Error! Unable to connect: ".$c->error()."\n";
}

# execute a POST method
my %resp;
if (!$c->lazydo ("/whatEverServerMethod",\%resp,methodpar1=>"blipp",methodpar2=>"blapp",methodparN=>"whatever")) {
   print "Error! Unable to execute method: ".$c->error();
} else {
   use Data::Dumper;
   print "RESULT: ".Dumper(\%resp);
}    

DESCRIPTION

HTTPS Client class to connect to a HTTPS-server and execute POST- and GET- methods. It takes a Content-class as the parameter upon instantiation and uses that to convert the parameters into the defined Content-class type for the server.

Upon a response the module then decode the return using the same Content-class type before returning the response as a HASH to the caller.

CONSTRUCTOR

new()

Instantiates the class.

Accepts the following parameters:

Besides this the constructor accepts any SSL parameter that the Net::HTTPS module accepts. See Net::HTTPS for more documentation.

METHODS

connect()

Attempts to connect to the HTTPS-server. It first connects with an unencrypted HTTP-connection and then upgrades to an SSL-connection when successful.

Returns 1 if successful, 0 when failure. Check the error()-method for more details in such cases.

connected()

Checks to see if the client is connected to the HTTPS-server or not?

Returns 1 if it is, 0 if not.

disconnect()

Disconnects from the HTTPS-server if already connected.

Returns 1 if successful, 0 if disconnected already.

do()

Executes a HTTP POST- og GET-method on the HTTPS-server and returns the result.

This method is not meant to be called directly, but can be if one so chooses to have the hassle with it.

The methods take these parameters in the following order:

This method takes the above parameters and then encodes the parameters based on the Content-class set for the instance and the executes a POST- or GET to the HTTPS-server. It then reads the response from the server and decodes it into HASH using the same Content-class instance. The resulting HASH is returned in the "response"-parameter above.

The method returns 1 upon successfully executing method on the HTTPS-server or 0 upon failure. Please check the error()-method for more information upon failure.

The response is read, as already mentioned, by looking at the HASH reference submitted to the method in the first place (parameter response).

lazydo()

A wrapper around the do()-method that is easier and quicker to use and that only performs HTTP POST-calls.

It takes these parameters in the following order:

This method executes the servermethod on the HTTPS-server by calling the do()-method.

The server response is returned in the already mentioned response-parameter.

The method returns 1 upon success, 0 upon failure. Please call the error()-method for more information on the failure.

error()

Returns the last error message from the class.