1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use strict;
use LWP::UserAgent;
### Message Parameter
my $parameter = @ARGV[0];
my @parameters = split( /;:;/, $parameter);
my $msg_node = $parameters[0];
my $ua = LWP::UserAgent->new;
my $response = $ua->post('https://xyz.com/CallLog',
[
msg_node => $msg_node
]);
if ($response->is_success) {
print "is success:\n", $response->content;
}
else {
print "is not success:\n", $response->status_line;
}
Quotesiehe LWP::UserAgent$ua->credentials( $netloc, $realm, $uname, $pass )
$ua->credentials("www.example.com:80", "Some Realm", "foo", "secret");
$ua->credentials("https://xyz.com/CallLog:443", "Some Realm", "username", "password");
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
my $req = HTTP::Request->new('GET', $ARGV[0]);
my $res = $ua->simple_request($req);
if($res->code == 401 && $res->header('WWW-Authenticate') =~ m/realm="([^"]+)"/) {
print "Realm: " . $1;
}
$ua->ssl_opts (SSL_ca_file => "path/to/big-ca-file.cert")
1
2
3
4
5
6
500 (Internal Server Error) Connect failed: connect: Unknown error; Unknown error
Content-Type: text/plain
Client-Date: yxz
Client-Warning: Internal response
500 Connect failed: connect: Unknown error; Unknown error
use LWP::Debug qw(+);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
LWP::UserAgent::send_request:: POST https://KundenDomain/CallLog/
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::UserAgent::request: Simple response: Internal Server Error
status_line:
500 Connect failed: connect: Unknown error; Unknown error
as_string:
500 (Internal Server Error) Connect failed: connect: Unknown error; Unknown error
Content-Type: text/plain
Client-Date: yxz
Client-Warning: Internal response
500 Connect failed: connect: Unknown error; Unknown error
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use strict;
use LWP::UserAgent;
use Crypt::SSLeay;
use LWP::Debug qw(+);
### Message Parameter
my $parameter = @ARGV[0];
my @parameters = split( /;:;/, $parameter);
my $msg_node = $parameters[0];
my $ua = LWP::UserAgent->new;
my $response = $ua->post('https://CustomerDomain/CallLog',
[
msg_node => $msg_node
]);
$ua->credentials("https://CustomerDomain/CallLog", "realm", "username", "password");
$ua->proxy('http://proxyserver:port');
if ($response->is_success) {
print "is success:\n", $response->content;
}
else {
print "is not success:\n", $response->status_line;
}
ua->credentials("CustomerDomain:443", "realm", "username", "password");
2011-10-12T08:52:37 a_abelsAuch so wie ich geschrieben habe, Domain:Port und nicht URL?Hallo,
ich habe nun die $ua->credentials und den $ua->proxy direkt nach dem $ua = LWP::UserAgent->new gesetzt.
QuoteWer weiß wie die Authentifizierung am Proxy und am Webserver wirklich läuft. Ich nicht.Wenn ich meinem (Büro) System das Skript nun ausführe bekomme ich weiterhin:
401 Unauthorized.
Beim Kunden bekomme ich weiterhin: 500 Connect failed.
QuoteWie? Was? Da ist eine Firewall mit Authentifikation davor? Oder was ist ISA?Bei den credentials habe ich ein Gedankenproblem: ich möchte mich ja am WebServer anmelden. Ich glaube aber, dass die Autorisierung über einen MS ISA Server geht!!!??? Was soll ich denn nun da eintragen?
QuoteAuch so wie ich geschrieben habe, Domain:Port und nicht URL?
$ua->credentials("poms-test.ts.fujitsu.com", "POMS2 HTTP Interface Login", "username", "password");
QuoteWie? Was? Da ist eine Firewall mit Authentifikation davor? Oder was ist ISA?
QuotePOST /CallLog HTTP/1.1
Reverse-Via: ABGISA4A
Host: poms-test.ts.fujitsu.com:443
Content-Type: application/x-www-form-urlencoded
User-Agent: libwww-perl/5.75
TE: deflate,gzip;q=0.3
Connection: Keep-Alive
Content-Length: 9
QuoteGET /CallLog HTTP/1.1
Reverse-Via: ABGISA4A
Host: poms-test.ts.fujitsu.com:443
Cookie: ISAWPLB{1D1E5963-5085-4C94-BEED-1230BA03921A}={8A76F960-EAAE-4A7A-9CAC-3EE9C6F38666}
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Authorization: Basic abcdefg
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Accept-Language: en-us
Connection: Keep-Alive
1 2 3 4 5
use HTTP::Cookies; my $cookie_jar = HTTP::Cookies->new( file => "$ENV{'HOME'}/lwp_cookies.dat", autosave => 1, );
$ua->cookie_jar($cookie_jar);
1 2
my $ie_ua = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)'; $ua->agent($ie_ua);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use strict;
use LWP::UserAgent;
use Crypt::SSLeay;
use LWP::Debug qw(+);
use HTTP::Cookies;
my $cookie_jar = HTTP::Cookies->new(
file => "$ENV{'HOME'}/lwp_cookies.dat",
autosave => 1,
);
### Message Parameter
my $parameter = @ARGV[0];
my @parameters = split( /;:;/, $parameter);
my $msg_node = $parameters[0];
my $ua = LWP::UserAgent->new;
my $ie_ua = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)';
$ua->agent($ie_ua);
$ua->cookie_jar($cookie_jar);
#$ua->credentials("poms-test.ts.fujitsu.com:80", "POMS2 HTTP Interface Login", "username", "password");
$ua->credentials('poms-test.ts.fujitsu.com:80', 'POMS2 HTTP Interface Login', 'username', 'password');
my $response = $ua->post('https://poms-test.ts.fujitsu.com/CallLog',
[
msg_node => $msg_node
]);
if ($response->is_success) {
print "\n\nis success (content):", $response->content, "\n\n";
}
else {
print "\n\nis not success (status_line): ", $response->status_line, "\n\n";
# print "\n\nis not success (content):", $response->content, "\n\n";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
HTTP::Cookies::add_cookie_header: Checking poms-test.ts.fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking .ts.fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking ts.fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking .fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking .com for cookies
LWP::UserAgent::send_request: POST https://poms-test.ts.fujitsu.com/CallLog
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::collect: read 622 bytes
LWP::Protocol::collect: read 932 bytes
HTTP::Cookies::extract_cookies: Set cookie ISAWPLB{1D1E5963-5085-4C94-BEED-1230BA03921A} => {8A76F960-EAAE-4A7A-9CAC-3EE9C6F38666}
LWP::UserAgent::request: Simple response: Unauthorized
is not success (status_line): 401 Unauthorized
#LWP-Cookies-1.0
1 2 3 4 5 6 7 8
my $response = $ua->get('https://poms-test.ts.fujitsu.com/CallLog'); if ($response->is_success) { print "\n\nis success (content):", $response->content, "\n\n"; } else { print "\n\nis not success (status_line): ", $response->status_line, "\n\n"; # print "\n\nis not success (content):", $response->content, "\n\n"; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
D:\test>posted_https.pl
LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
HTTP::Cookies::add_cookie_header: Checking poms-test.ts.fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking .ts.fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking ts.fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking .fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking .com for cookies
LWP::UserAgent::send_request: GET https://poms-test.ts.fujitsu.com/CallLog
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::collect: read 622 bytes
LWP::Protocol::collect: read 932 bytes
HTTP::Cookies::extract_cookies: Set cookie ISAWPLB{1D1E5963-5085-4C94-BEED-1230BA03921A} => {8A76F960-EAAE-4A7A-9CAC-3EE9C6F38666}
LWP::UserAgent::request: Simple response: Unauthorized
is not success (status_line): 401 Unauthorized
LWP::UserAgent::request: ()
HTTP::Cookies::add_cookie_header: Checking poms-test.ts.fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: - checking cookie path=/
HTTP::Cookies::add_cookie_header: - checking cookie ISAWPLB{1D1E5963-5085-4C94-BEED-1230BA03921A}={8A76F960-EAAE-4A7A-9CAC-3EE9C6F38666}
HTTP::Cookies::add_cookie_header: it's a match
HTTP::Cookies::add_cookie_header: Checking .ts.fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking ts.fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking .fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking fujitsu.com for cookies
HTTP::Cookies::add_cookie_header: Checking .com for cookies
LWP::UserAgent::send_request: POST https://poms-test.ts.fujitsu.com/CallLog
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::collect: read 738 bytes
LWP::Protocol::collect: read 816 bytes
LWP::UserAgent::request: Simple response: Unauthorized
is not success (status_line): 401 Unauthorized
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use strict;
use WWW::Mechanize;
use Crypt::SSLeay;
my $url = "https://poms-test.ts.fujitsu.com/CallLog/";
my $mech = WWW::Mechanize->new( autocheck => 1 ); # initalize
#$mech->credentials("username", "password");
$mech->credentials('poms-test.ts.fujitsu.com:80', 'POMS2 HTTP Interface Login', 'username', 'password');
#my $content = $mech->get($url); # get content of url
my $response = $mech->post('https://poms-test.ts.fujitsu.com/CallLog',
[
msg_node => 'meinKnoten',
]);
if ($response->is_success) {
print "\n\nis success (content):", $response->content, "\n\n";
}
else {
print "\n\nis not success (status_line): ", $response->status_line, "\n\n";
# print "\n\nis not success (content):", $response->content, "\n\n";
}
print "url:'$url'\ncontent:'$response'\n";
exit;
1
2
3
4
5
6
7
8
9
10
11
GET https://poms-test.ts.fujitsu.com
Authorization: Basic ****************=
User-Agent: lwp-request/5.834 libwww-perl/6.02
GET https://poms-test.ts.fujitsu.com --> 401 Unauthorized
GET https://poms-test.ts.fujitsu.com --> 405 Method Not Allowed
Connection: Keep-Alive
Date: Fri, 14 Oct 2011 15:21:25 +0200
Server: Poms HTTP Interface 1.1
Allow: PUT, POST
...
1
2
3
4
5
6
7
8
9
10
11
12
POST https://poms-test.ts.fujitsu.com
Authorization: Basic *********=
User-Agent: lwp-request/5.834 libwww-perl/6.02
Content-Length: 0
Content-Type: application/x-www-form-urlencoded
POST https://poms-test.ts.fujitsu.com --> 401 Unauthorized
POST https://poms-test.ts.fujitsu.com --> 444 Dokument missing
Connection: Keep-Alive
Date: Fri, 14 Oct 2011 15:23:57 +0200
Server: Poms HTTP Interface 1.1
.....
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
use strict; use warnings; use LWP::UserAgent; my $pw='abcdefg'; my $us='1234567'; my $url = "https://poms-test.ts.fujitsu.com/CallLog"; my $response; my $ua = LWP::UserAgent->new; $ua->requests_redirectable(undef); # Redirects ausschalten! $ua->credentials("poms-test.ts.fujitsu.com:443", "POMS2", $us, $pw); my $response = $ua->post($url,[0=>0]); print $response->status_line; print $response->decoded_content;