SSH problem

D

Dianne van Dulken

Hi,

I'm having some trouble connecting to a third site via both SSleay and
UserAgent. I think it might have something to do with the
certificates, but I can't work out exactly what. I keep on getting a
500 error, when I am expecting a Location moved response.

Would someone mind having a quick look over my code and seeing if
there is something blatently obviously wrong that I'm missing.

Thank you very much

Dianne


!/usr/bin/perl

use strict;
use Net::SSLeay;
use LWP::Debug qw(+);
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;

$ENV{HTTPS_DEBUG} = 1;
$ENV{HTTPS_VERSION} = 3;

$Net::SSLeay::trace = 2;

$ENV{HTTPS_CERT_FILE} = 'certs/oilolig.pem';
$ENV{HTTPS_KEY_FILE} = 'certs/oilolig.pem';

sub connectto {
my ($thisurl, $method) = @_;
print "CONNECTING to $thisurl via $method \n";
my $location;
my $cookie;
if (($method eq 'post') ||($method eq 'get')) {
my ($page, $response, @headers);
my ($url1, $sub_url1) = &spliturls($thisurl);
print "split urls are $url1 and $sub_url1 \n";
if ($method eq 'post') {
print "attempting to connect via post \n";
($page, $response, @headers) =
Net::SSLeay::post_https($url1, 443, $sub_url1, '');
}
if ($method eq 'get') {
print "attempting to connect via get \n";
($page, $response, @headers) =
Net::SSLeay::get_https($url1, 443, $sub_url1, '');
}
for (my $i = 0; $i < $#headers; $i+=2) {
print "header $i : $headers[$i] = " . $headers[$i+1] . "\n";
if ($headers[$i] eq "LOCATION") { $location = $headers[$i+1];}
if ($headers[$i] eq "COOKIE") {$cookie = $headers[$i+1];}
}
return ($location, $cookie);
} else {
# otherwise, we want to connect via useragent
print "UA connect \n\n";
my $ua = LWP::UserAgent -> new();
my $cookie_jar = HTTP::Cookies->new(
file => "lwp_cookies.dat",
autosave => 1,
);

$ua->cookie_jar( $cookie_jar );
my $request = HTTP::Request->new(GET => $thisurl);

my $res = $ua->request($request);
my $location = $res->header('LOCATION');
my $cookie = $res->header('COOKIE');
print "location is $location \n cookie is $cookie \n";
if ($res->is_success) {
print "Connection to UA is ok\n";
}
else {
print "Connection to UA gives " . $res->status_line . "\n";
}
return "res is $res \n";
}
}

sub spliturls {
my ($url1) = @_;
print "SPLITURLS url1 is $url1 \n";
my ($junk, $url2, $sub_url2);
($junk, $url2) = split('//', $url1);
($url2, $sub_url2) = split('/', $url2, 2);
return ($url2, '/'.$sub_url2);
}


my $url1 = 'https://shopfront3.telstra.com.au/LOLOSTGCb2b/services/ProductCreateImmService';
my ($url2, $cookie) = &connectto($url1, 'post');
print "url2 : $url2 \n";
my ($url3, $cookie2) = &connectto($url2, 'ua');
print "url3 : $url3 \n";
 
B

Brian McCauley

Subject: SSH problem

There is no mention of SSH anywhere but in the subject. On a scale of
0 to 10 for usefullness your subject scores about -2.
I'm having some trouble connecting to a third site via both SSleay and
UserAgent. I think it might have something to do with the
certificates, but I can't work out exactly what. I keep on getting a
500 error, when I am expecting a Location moved response.

Would someone mind having a quick look over my code and seeing if
there is something blatently obviously wrong that I'm missing.

Indentation and warnings. Nither of these would directly account for
the error but they are blatently missing. The lack of indentation
makes it unreasonably difficult for anyone trying to help you to
understand the logic.

You say you are UserAgent (presumably LWP::UserAgent) but you also
appear to be using Net::SSLeay::get_https. This seems odd to me.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top