[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 512
  • Last Modified:

Post file to remote server using PERL??

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
jimmyjoe
Asked:
jimmyjoe
1 Solution
 
ozoCommented:
what's the URL of the form?
0
 
TintinCommented:
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
 
jimmyjoeAuthor Commented:
0
 
ItatsumakiCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now