Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

www::mechanize question

Status
Not open for further replies.

kaancho12

Technical User
Joined
Feb 22, 2005
Messages
191
hi,
i need to use to upload a file to a CGI script...any tips on how to go about doing it????
thanks
ko12
 
i am not so familiar with the mechanize --so actually i was wondering how to post to a cgi script in the first place....is there a method that mechanize has that allows you invoke a cgi script....probably then i can pass the parameters.
thanks
 
I'm not familiar with mechanize but it'll basically simulate interacting with a web page. Therefore if the cgi script has a form that submits to it, you can use machanize to browse the form, fill it out, and submit it. See the documentation at The 'field' method would be what you would use to fill out the fields on the form, particularly the file upload field.

However, it may be easier just to submit data to the cgi script directly without going through the form. You can do this with LWP::UserAgent and HTTP::Request::Common.
 
hi - thank you philote for your help. After going through the notes and some programming i came up with the code below to try and post to a 'cgi' script...but it gives me this error:
Can't locate object method "credentials" via package "HTTP::Headers" at (eval 4) line 1.
Any idea what i might be doing wrong:
#!/usr/bin/perl -w
use HTTP::Request::Common;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(POST =>'$req->credentials('$req->content_type('form-data',Content =>[ cApp => '1', db => 'prod',filename => ["/var/www/html/prod.xml"]]);
# Pass the request to the user agent and get a response back
my $res = $ua->request($req);
if ($res->is_success){
print $res->content;
}else{
print $res->status_line;
}
 
Credentials is a method of LWP::Useragent, not HTTP::Request::Simple. I did a search on this site and found thread219-682844 that may give you some good info.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top