Forum Moderators: coopster & phranque

Message Too Old, No Replies

Setting <form> data in perl

         

CornFlakes

8:56 pm on May 23, 2005 (gmt 0)

10+ Year Member



From my perl script, I'd like to set a couple of form "parameters" and redirect to an ASP page. I currently get to the same ASP page via a "submit" button with form fields set, and I'd like to mimic that behavior in my perl script. How can I do it?

lexipixel

11:50 pm on May 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not sure if this is what you are looking for, but you can translate what would otherwise be FORM DATA by adding it after a question mark on the target URL, ie-

?name=John&Address=123%20Main%20Street&zip=12345

Is that what you're looking for?

CornFlakes

3:31 pm on May 24, 2005 (gmt 0)

10+ Year Member



That's a lot like what I want, but I'd sure like to do it without polluting the URL (more like POSTing a form than GETting it).

Can I do that?

rocknbil

5:05 pm on May 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Curl will do it:

$result = `curl -d 'var1=$var1&var2=$var2...' $destination`;
or
$result = qx¦curl -d 'var1=$var1&var2=$var2...' $destination¦;

print "content-type: text/html\n\n";
print "$result";

curl sends any data to $destination. The entire response is captured and stored in $result, which you print out.

This can fool you, or add another layer of security, depending on how you see it. The displayed URL in the address bar will be wherever you call curl from. For example, if you're calling curl from [example.com...] and $destination is [wherever.com...] the address bar will NOT read wherever.com - it will still say example.com/test.cgi. The end user will never know you've left the site to do something else.

The reason this is of mention is you have to watch any page links when using curl.

CornFlakes

5:14 pm on May 24, 2005 (gmt 0)

10+ Year Member



I can see where that would be good for calling someone else's script from mine. What I was actually looking for, though, was a browser re-direct, with parameters but without a polluted URL. I'd like to end up on the ASP page, and I'd like for the ASP page to not know whether it was called from my cgi or simply visited as the target of a "submit" button.

I'll definitely remember about curl, though.

rocknbil

3:55 pm on May 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hmm I've been back and forth two days in a row between your initial post and your last one, and I guess it's not penetrating my cro-magnon unibrow. :-) If $destination = your .asp script, it sends the variables to it just as if data were submitted to it, captures it and stores it in $result, then prints the whole wad out to the browser.

CornFlakes

5:15 pm on May 26, 2005 (gmt 0)

10+ Year Member



Right. But I don't want to run an ASP script and come back to my perl script. I want the script to send the browser to the ASP page (which I'm currently doing with 'print "Location: $asp\n\n"). The trouble for me is that any form data that was POSTed to the perl script doesn't get POSTed to the ASP page when I do that. Maybe I don't understand, but using the curl statement doesn't look like it would do it, either.

lexipixel

5:28 pm on May 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




Not sure, but maybe

$ENV{'REDIRECT_URL'}

and

$ENV{'REDIRECT_QUERY_STRING'}

may hold the answer...

SamBru

12:25 am on May 30, 2005 (gmt 0)



You could always do it using javascript.
(not syntax checked, but you get the idea...)


print qq(
<html>
...
<body onload="javascript:document.form1.submit()">
<h1> Redirecting soon... </h1>
<form name="form1" action="myscript.asp" method="post">
<input type="hidden" value="23" name="magical">
</form>
</body>
</html>
);