It would be great if someone could help convert this function from Php to Perl, basically this function is meant to get contents of a https url. Right now I'm not good with Perl, I haven't learnt on how to use cURL just yet.
function curl_get_content($url)
{
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($handle, CURLOPT_SSLVERSION, 3);
$data = curl_exec($handle);
curl_close($handle);
return $data;
}
Thanks!
EDIT:
I attempted to use this
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 });
my $header = HTTP::Request->new(GET => $URL);
my $request = HTTP::Request->new('GET', $URL, $header);
my $response = $ua->request($request);
if ($response->is_success){
print "URL:$URL\nHeaders:\n";
print $response->headers_as_string;
}elsif ($response->is_error){
print "Error:$URL\n";
print $response->error_as_HTML;
}
But it keeps giving me server error: 500.
sub getContent { my ($URL) = @_; my $agent = LWP::UserAgent->new(env_proxy => 0,keep_alive => 1, timeout => 30); my $header = HTTP::Request->new(GET => $URL); my $request = HTTP::Request->new('GET', $URL, $header); my $response = $agent->request($request); return $response; }use LWP::Simple; print get("https://github.com");