Solved

Post file to remote server using PERL??

Posted on 2003-11-07
4
483 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
Comment Utility
what's the URL of the form?
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
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
Comment Utility
0
 
LVL 2

Accepted Solution

by:
Itatsumaki earned 200 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now