you can send GET data like this:
print "Location:hello.cgi?text=hello+world\n\n";
but what if you don't want the?text=hello+world to appear?
Something like this, perhaps?
postdata("hello.cgi",text => "hello+world");
print "content-type: text/html\n\n";
print "$result";
Curl is one way to post data silently. The -d switch means that the first param is data to be sent, second is the URL, what gets returned is stored in result. Depending on what the url sends back, this can be an entire page, a delimited string, or more key/value pairs.
If I have a perl CGI script which I execute to post form data can I use curl to do it?
e.g. <a href="blah.cgi">BUY WIDGET</a>
and blah.cgi contains the form data to be posted
e.g.
[example.com...]
I tried the code you posted here but it only displays the curl command in the browser window and does not actually invoke the form destination URL.
#!/usr/bin/perluse CGI;
$result = qq¦curl -d q=value+1 [google.com...]
print "content-type: text/html\n\n";
print "$result";
Sorry Phraseology and adni, it doesn't work because I used qq and not qx, which executes.
But you guys/gals should have known that. :-) It was a test, yeah, that's it . . .
The reason I did that accidentially is I sometimes have very very long curl strings and it's easier to debug if I word-quote it first, then execute it:
$string = qq¦curl -d key1=value+1&key2=value+2 [url_to_post_to.com¦;...]
$result = qx¦$string¦;
##OR $result = `$string`;
print "content-type: text/html\n\n";
print "$result";
That should successfully store the RESULTS of what is curled in $result.
That should successfully store the RESULTS of what is curled in $result.
Rocknbill,
The results are returned to the perl script - but thats not what I want. I want the script to post the data and the results to be sent back to the browser.
I know I can simply print the $result but the browser will still point to site-A. Whereas if the user submits an html form on a page he is directed to site-B as the form is processed.
Or am I just muddying the waters even more?
AAARGH! No, I have no idea where those came from. This message board, apparently.
(tries again) :-D
$string = qq¦curl -d key1=value+1&key2=value+2 [url_to_post_to.com¦;...]
$result = qx¦$string¦;
##OR $result = `$string`;
I know I can simply print the $result but the browser will still point to site-A. Whereas if the user submits an html form on a page he is directed to site-B as the form is processed.
So why wouldn't this work?
$string = qq¦curl -d key1=value+1&key2=value+2 [url_to_post_to.com¦;...]
$result = qx¦$string¦;
## Do something with $result
print "Location: somwhere_else.html\n\n";
Or maybe you're looking for a forked process? Yah I think you might have lost me. :-)
Let me give you a real world example of what I am trying to do. I am going to use google as an example (I dont want to post specific urls here but I think using google as an example will be okay).
Site-A has a google search box form.
You enter a search term(s) and submit!
The browser is directed to site-B (google.com) and a list of results are displayed - voila!
What I want to do is...
Site-A has a link to a script on site-A.
Perl script on site-A simulates the form filling
process and submits form.
Then somehow pass control back to the browser so that the browser gets the results from site-B (even though the form was submitted by a script).
Maybe the answer is simple and I just dont see it.
print "welcome to site A\n";
print qq¦<form action="site_a.cgi">¦;
.....
## We don't need to curl for site A, it's right here.
$site_a_results = &yourSearchOutput;
$string = qq¦curl -d key1=value+1&key2=value+2 [site_b.com¦;...]
$site_b_results = `$string`;
print "here are results from site A:$site_a_results\n\n";
print "here are results from site B:$site_b_results\n\n";
? :-)
ex:
in the address bar: [google.com...]
hidden variables, contained in POSTDATA: q=this+is+a+search
INSTEAD OF:
in the address bar: [google.com...]