wataguy has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to read a page, change a form value, and then reload the page.

I can get the page OK, but I haven't been able to do the rest.

I've tried things like this:

$ua = LWP::UserAgent->new; my $req = POST 'http://thesite/thepage.aspx', [ errors => 0 ]; $html = $ua->request($req)->as_string; $html =~ /name="__VIEWSTATE" value="([^"]+)"/s; $viewState = $1; my $req = POST 'http://thesite/thepage.aspx', [ __EVENTTARGET => 'theItemID', __EVENTARGUMENT => 'newValue', __VIEWSTATE => $viewState, errors => 0 ]; $html = $ua->request($req)->as_string;

but no joy.

I'll be happy to buy anyone who reveals the secrets of this mystery a beer the next time they're in Phnom Penh. Thanks.

Replies are listed 'Best First'.
Re: ASP postBack from Perl?
by Jaap (Curate) on Jun 11, 2005 at 10:40 UTC
    Most of the time a GET request works too for form submission, so you might wanna try something like this:
    use LWP::Simple; my $baseURL = "http://thesite/thepage.aspx"; my page = get($baseURL); if ($page =~ m/name="__VIEWSTATE" value="([^"]+)"/s) { my $viewState = $1; my $submitResult = get("$baseURL?__EVENTTARGET=theItemID&__EVENTARGU +MENT=newValue&__VIEWSTATE=$viewState"); }
    Warning: untested code.
      The problem with that is that __VIEWSTATE for the page I'm reading is about 200K (thanks, Microsoft!), which blows the character limits on GET — running that code gives me a "broken pipe".
Re: ASP postBack from Perl?
by kaif (Friar) on Jun 13, 2005 at 04:14 UTC

    [id://wataguy], can you help us by saying what "no joy" means? That is, is Perl throwing an error, is the page not liking your request, etc.? I personally don't have an example ASP page I could try your code on, so by providing more information, you may be able to help other monks help you. Thank you.

    Update: By the way, to other people looking at this node, the modules the OP is using are LWP::UserAgent and HTTP::Request::Common. Perhaps this is clear to those who work with such things more often, but it is good to know nonetheless.

      Sorry about the long reply lag — I really am in Phnom Penh, and time zone differences, and sometimes spotty net access, take their toll.

      The page I'm trying to grab is http://icasualties.org/oif/Details.aspx. By default, this gives you the most recent 20 names; I'd like to grab all of them at once. So what I really want to do is get the page, extract the total casualty count, and reload the page with the entire casualty list on it.

      Anyway, when I try my code, I just get back the original page with 20 names on it; that's what I meant by "no joy"

Re: ASP postBack from Perl?
by EvanCarroll (Chaplain) on Aug 21, 2008 at 20:28 UTC