Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Posts
    3

    Unanswered: Post Webpage Content

    I am kinda new to Perl but i am trying, what basically i want to do is login to webpage using post data and go to particular page parse it and get webpage content.Though i havent reached to the point for parsing i want to go step by step.
    But I get error Response status is: 405 Method not allowed error.
    Help Needed

    <code>
    #!/usr/bin/perl

    use LWP::UserAgent;
    use HTTP::Cookies;
    use HTTP::Request::Common ;
    #!/usr/bin/perl

    use LWP::UserAgent;
    use HTTP::Cookies;
    use HTTP::Request::Common ;
    use HTTP::Request;
    use HTTP::Response;
    use HTTP::Headers;
    use HTML::Parser;
    use XML::Parser;

    my $login = { username => 'guestuser',
    userPassword => 'temp',
    ip_address => '10.70.30.20',
    successURL => 'home.asp',
    submit => 'login', };


    my $ua = LWP::UserAgent->new( keep_alive => 1 );
    timeout => 30 );

    my $cookie_jar = HTTP::Cookies->new;
    $cookie_jar->add_cookie_header($request);
    $ua->cookie_jar( $cookie_jar );
    my $header = HTTP::Headers->new( Content_Type => 'text/html',
    User_Agent => 'Release_Build/1.0' );
    $header->as_string;
    my $request = HTTP::Request::Common::POST( 'http://10.1.19.22', $login,
    User_Agent => 'Release_Build/1.0' );

    $request->as_string;

    my $response = $ua->request( $request );
    print $response->as_string();

    $cookie_jar->extract_cookies($response);
    $cookie_jar->as_string();

    while ($response->is_redirect) {
    my $location = $response->header( "location" );
    $request = HTTP::Request->new( "GET", "http://10.1.19.22/" . $location, $header );
    print $request->as_string;
    $response = $ua->request( $request );
    print $response->as_string();
    }

    unless ($response->is_success) {
    print "Response status is: ", $response->status_line();
    return undef;
    }

    </code>

  2. #2
    Join Date
    Sep 2002
    Location
    Germany, near Aachen
    Posts
    120
    Have a look at WWW::Mechanize from CPAN (http://search.cpan.org/~petdance/WWW...W/Mechanize.pm), it should make things like that easy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •