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

Hello!

I need a perl script to redirect to an ASP page, with sending some data. When I do it to send to another Perl page I use:
print "Location: $url?$data\n\n";
and it works fine.

If $url is an .asp script, the data is never considered as received (or correctly received).

I also tried using LWP::Post, LWP::Simple, same thing, the data is never sent.

I also tried to "escape" $data as I read somewhere:
my $EscapedStr = URI::Escape::uri_escape($data);
It does not change anything.

The only way is to submit manually a POST form to the url, and then here it is working. But I need a direct call from my perl script.

Note: The perl script must just redirect to the asp page with the data, no need to receive anything back.

Thank you!

Replies are listed 'Best First'.
Re: Sending data to an ASP link
by Anonymous Monk on Mar 01, 2009 at 06:59 UTC
    What did you actually try (show your code)? What does that asp page expect? What is actually sent over the wire ( http://wireshark.org, Live HTTP Headers)?
    #!/usr/bin/perl -- use CGI(); my $data = 'http://bar/?%2fb=c;d=e'; my $uri = 'http://foo/asp.asp?'.CGI::escape($data); print CGI->redirect( -nph => 1, -uri => $uri, ); __END__ $ perl test.pl |cat -v HTTP/1.0 302 Found^M Server: cmdline^M Status: 302 Found^M Date: Sun, 01 Mar 2009 06:57:57 GMT^M Location: http://foo/asp.asp?http%3A%2F%2Fbar%2F%3F%252fb%3Dc%3Bd%3De^ +M ^M # perl test.pl | cat -v
    There's no need to actually LIE, no such thing as LWP::Post
      I just try to post data to
      https://perfectmoney.com/api/step1.asp If no data is received the page redirects to the index page.

      And when I try your snippet (Thank you for it :), I get a "302 moved" reply, or a blank page if I run the script in a browser from the browser.

      If I embed the data in a html POST form, it works (Even if the data is wrong, I get some error messages from the asp script, that is normal).
      About LWP (Post) I mean in fact

      use LWP::Simple::Post qw(post post_xml);
      use LWP::UserAgent;
      use LWP::Simple;

      Rather an error writing than a LIE!
        Letters In Error :)
Re: Sending data to an ASP link
by Marshall (Canon) on Mar 01, 2009 at 20:35 UTC
    I am sorry that I can't post some working code as I suffered a major storm that overwhelmed my surge protection and killed the P/S and a few HD's in my computer. Talk about a BUMMER!

    I did have some code that used SSL to log-in to a M$ site with .ASP server pages.

    Some basics that I remember:
    1. An ASP site will serve up something called the "VIEWSTATE". Use your browser "view source page" to see what this looks like.
    2. Example: <input type="hidden" name="__VIEWSTATE" value="dDw3MTg3NjQ5NzQ7dDw7bDxpPDA+Oz47bDx0PDtsPGk8OD47PjtsPHQ8O2w8aTw1Pjs+O2w8dDw7bDxpPDI+Oz47bDx0PHA8bDxWaXNpYmxlOz47bDxvPHQ+Oz4+Ozs+Oz4+Oz4+Oz4+Oz4+Oz7YipIMUB9WWjrfFB7uRaLUHWL6WQ==" />'
    3. If YOU are going to talk with this web-site, you send back the the "VIEWSTATE" that it sent you in response to your last POST. The VIEWSTATE will change with every response to you. This requires regex or other magic to extract the VIEWSTATE (not that hard). The basic purpose of this VIEWSTATE is to drive the storage and maintenance of the current state(what page you are looking at, etc) to the client instead of on the server.
    Hope this idea helps you proceed...