Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I need to access a site where the login page uses an https URL and then get data off an http URL.
I'm approaching this problem by first doing a GET HTTP::Request of the login page and then a POST HTTP::Request to the login page and providing the username and password.

I then plan to do another GET to the data url.


My problem is in the POST.

When I look at the returned page, it is the same as what gets returned for the initial GET, where the user is getting prompted for the login info.


I'm new to perl and would really appreciate any advice.

Here is my code:

use LWP::UserAgent; use HTTP::Cookies; use LWP::Simple; use HTTP::Request; use strict; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)"); my $cj = HTTP::Cookies->new(file => "lwp.cookie", autosave => 1); $ua->cookie_jar($cj); $cj->save; my $req1 = HTTP::Request->new(GET => 'https://www.samplesite.com/myacc +ount/default.asp?sp=login'); my $res1 = $ua->request($req1); if ($res1->is_success) { print "1st step complete\n"; } else { print "Error: " . $res1->status_line . "\n"; } my $req2 = HTTP::Request->new(POST => 'https://www.samplesite.com/myac +count/default.asp?sp= login', [username => "samp2", password => "data362"],); if ($res2->is_success) { print $res2->content; print "Step 2 ocmplete\n"; } else { print "Error: " . $res2->status_line . "\n"; }

In reply to How do I access a password protected site and access data? by jaydon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (2)
    As of 2018-07-22 07:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (452 votes). Check out past polls.

      Notices?