The lwpcook documentation (that comes with the LWP bundle) provides very helpful examples of how to use the LWP modules. Here's the section on POSTing data:
POST
There is no simple procedural interface for posting data to a WWW serv
+er. You
must use the object oriented interface for this. The most common POST
operation is to access a WWW form application:
use LWP::UserAgent;
$ua = new LWP::UserAgent;
my $req = new HTTP::Request 'POST','http://www.perl.com/cgi-bin/BugG
+limpse';
$req->content_type('application/x-www-form-urlencoded');
$req->content('match=www&errors=0');
my $res = $ua->request($req);
print $res->as_string;
Lazy people use the HTTP::Request::Common module to set up a suitable
POST request message (it handles all the escaping issues) and has a
suitable default for the content_type:
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = new LWP::UserAgent;
my $req = POST 'http://www.perl.com/cgi-bin/BugGlimpse',
[ search => 'www', errors => 0 ];
print $ua->request($req)->as_string;
The lwp-request program (alias POST) that is distributed with the
library can also be used for posting data.
I've used the lazy approach to good effect. | [reply] [d/l] |
| [reply] |
Into a command prompt type:
perldoc perldoc
and you will learn how to get documentation of Perl
things installed on your system. Not to be underestimated
is that you get documented the version that you actually
have installed. And if you become competent (which is
mainly a question of learning to use "/pattern" then "n")
at finding stuff in those pages you will generally find it
faster to find things in that documentation than through
websites. | [reply] [d/l] |
| [reply] [d/l] |
davorg wrote a good series of articles in Perl Month explaining how to get documentation using the command perldoc.
They start in Issue #1
| [reply] |
Here's an example for you, that works OK, except for a bug that I need help with. the POST is here, and the form is below. The thing is, I can't get it to set the checkbox values and I can't find any doc anywhere to tell me how. I did this working from Orwant & Gruhl's article in TPJ 4:1.
Any help would be a godsend!
sub getLinkParse
{ use LWP::UserAgent; use HTTP::Request::Common;
$sentence = "This is a test sentence.";
$response = (new LWP::UserAgent)->request(POST
'http://www.link.cs.cmu.edu/cgi-bin/link1/construct-page-4
+.cgi#submit',
[ Sentence => $sentence,
Constituents => "1", <<<< this is a checkbox
NullLinks => "1", <<<< this is a checkbox
AllLinkages => "OFF",
LinkDisplay => "on",
ShortLength => "6",
PageFile => "/docs/submit-sentence-4.html",
InputFile => "/scripts/input-to-parser",
Maintainer => "sleator\@cs.cmu.edu" ] );
exit -1 unless $response->is_success;
$_ = $response->{_content};
print $_;
}
This is the origianl form on the site:
<FORM METHOD="POST" ACTION="/cgi-bin/link1/construct-page-4.cgi#submit
+">
<textarea name="Sentence" MAXLENGTH=200 wrap=virtual rows=3 cols=70><
+/textarea><br>
<INPUT TYPE="checkbox" NAME="Constituents" CHECKED>Show constituent tr
+ee
<INPUT TYPE="checkbox" NAME="NullLinks" CHECKED>Allow null links  
+;
<INPUT TYPE="checkbox" NAME="AllLinkages" OFF>Show all linkages
<INPUT TYPE="HIDDEN" NAME="LinkDisplay" VALUE="on">
<INPUT TYPE="HIDDEN" NAME="ShortLength" VALUE="6">
<INPUT TYPE="HIDDEN" NAME="PageFile" VALUE="/docs/submit-sentence-4.ht
+ml">
<INPUT TYPE="HIDDEN" NAME="InputFile" VALUE="/scripts/input-to-parser"
+>
<INPUT TYPE="HIDDEN" NAME="Maintainer" VALUE="sleator@cs.cmu.edu">
<br>
<INPUT TYPE="submit" VALUE="Submit one sentence">
<br>
</FORM>
| [reply] [d/l] |
Checkboxes without explicit VALUE fields return "ON". At least, in web browsers that follow the specifications. :)
Try that instead of "1".
| [reply] |
Thanks for the suggestion re checkboxes.
I tried "ON", "CHECKED", "1", "Dammit" -- none of them worked.
In general, where can I find more information about this? I'm sure my next problem will have radio buttons or something else I don't know how to do! ...
| [reply] |