Solved

Post file to remote server using PERL??

Posted on 2003-11-07
4
502 Views
Last Modified: 2013-12-25
1. A form resides on a remote server.
2. I want a PERL script to simulate filling in the form, including a file field, and then submittnig it.
3. Display the resulting page.

So basically I need to post several fields(one of which is a file field) to a server and then display the results.

JJ
0
Comment
Question by:jimmyjoe
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 9711033
what's the URL of the form?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 9711776
LWP::UserAgent is your tool, eg:

use LWP::UserAgent;
  $ua = LWP::UserAgent->new;  my $req = HTTP::Request->new(POST => 'http://www.perl.com/cgi-bin/BugGlimpse');
  $req->content_type('application/x-www-form-urlencoded');
  $req->content('match=www&errors=0');  my $res = $ua->request($req);
  print $res->as_string;
0
 

Author Comment

by:jimmyjoe
ID: 9712321
0
 
LVL 2

Accepted Solution

by:
Itatsumaki earned 200 total points
ID: 9724060
I think WWW::Mechanize is better for this than LWP::UserAgent
I use this exact approach to automate testing of CGI-based sites with Test::More.
Here is some code to do what you are asking.

###
use WWW::Mechanize;

my $url = 'http://xxx.xxx.xxx.xxx/cgi-bin/addvalues_entry.cgi?user_id=qwerty';

my $mech = WWW::Mechanize->new();

$mech->get($url);

$mech->form_number(1);
$mech->field('datafield', '10-Nov-2003');
$mech->field('filename', 'abcdabcd.zyx');
$mech->click('Submit');

print $mech->title(), "\n";
print $mech->content();
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question