Basically, if you are to access the HTTPS URL via browser, it will prompt you to verify the certificate which you have to accept before you actually be able to access it successfully.
To do it via back-end, we will have to do the same but this time, no interface.
First, we need to do SSL verification on the actual server that you will be using to access the URL, and to do that, we will use LYNX command and save the certificate if prompted.
Please see sample syntax below.
lynx https://example.mydomain.com/myscript.php..
If you don't have LYNX, you can do the normal way by accessing it via the browser. All you need to do is to access the browser of the actual server and save the certificate from there.
To check if successful, try to access the URL again, and you should not be prompted to save the certificate again. Hence, saving certificate is not successful.
Once okay with the certificate, we are now good to use LWP library to access the URL.
Please take note that the libraries below should be installed in your server.
- LWP::UserAgent
- HTTP::Request
- Crypt::SSLeay
The script below will be able to access the HTTPS URL. Hope you like it!
#!/usr/bin/perl
use LWP;
my $url = 'https://example.mydomain.com/myscript.php';
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
$ua->timeout(60000);
my $res = $ua->get($url);
print "result: $res\n";
1;
No comments:
Post a Comment