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 LWP::UserAgent; my $url = 'https://server.de/upload/topic123.php'; my $ua = LWP::UserAgent->new; $ua->default_header('X-Requested-With' => 'XMLHttpRequest'); $ua->timeout(180); $ua->requests_redirectable(undef); # Redirects ausschalten! $ua->credentials(server.de:Port', 'realm', 'abcdef', '123456'); my $response = $ua->post($url); if ($response->is_success) { print $response->decoded_content; } else { die $response->status_line; }
401 Unauthorized at C://Apache/cgi-bin/Bearbeiten.pl line 58
1 2 3 4 5
$h = HTTP::Headers->new(); # mit $h eigene Header hinzufügen, siehe POD my $req = HTTP::Request->new('POST', $url, $h, $content); ^ Header-Object
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
use strict; use LWP::UserAgent; use HTTP::Request; use CGI; use CGI::Carp qw(fatalsToBrowser); my $cgi = new CGI; my $aktion = CGI::param('?name'); my $var = CGI::param('referenz'); #my $url1 = 'https://server.de/topic/?name=stefan&id=r_ft=anything'; my $url1 = 'https://server.de/topic/'; my $ua = LWP::UserAgent->new; $ua->add_handler("request_send", sub { shift->dump; return }); $ua->add_handler("response_done", sub { shift->dump; return }); my $h = HTTP::Headers->new(Content_Type => 'text/html; version=3.2', 'X-Requested-With' => 'XMLHttpRequest'); $h->user_agent('Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0)'); my $req = HTTP::Request->new( 'POST', $url1,['referenz => $var','r_format =>$res_format'],$h); my $response = $ua->request($req); if ($response->is_success){ #print $response->decoded_content; } else { print "Failed: \n"; print $response->status_line, "\n"; }
Client-Warning: Internal response Not a SCALAR reference at C:/Perl/lib/LWP/Protocol/http.pm line 193.\n Failed: 500 Not a SCALAR reference
1 2 3 4 5 6
# Request und die erforderlichen Parameter my $req = POST $url, Content => [ nick => 'Otto', login => 1, ];
my $aktion = CGI::param('?name');
my $aktion = CGI::param('name');
1 2
my $content="name=$aktion&referenz=$var&r_format=$res_format"; my $req = HTTP::Request->new( 'POST', $url1, $h, $content);