From: cerr on
Hi There,

I'm using libwww to post data to a form. Once data is posted, the
server would send me back a file. How can i retrieve and safe this
file?
I'm posting the data with below code:

$response = $browser->get($url);
print $response->header('WWW-Authenticate'),"\n";
die "Error at $url\n ", $response->status_line, "\n Aborting"
unless $response->is_success;
#print "Authentication successful! Got ",$response->content_type, "
document!\n";
# Create a post request
my $post = HTTP::Request->new(POST => $PostPage);
#print "Posting data to \"$PostPage\"\n";
$post->content_type('application/x-www-form-urlencoded');
$post->content('export_profile=Current%20Profile');
# Pass request to the user agent and get a response back
my $res = $browser->request($post);

# Check the outcome of the response
if ($res->is_success) {
print $res->content , "\n";
}
else {
print $res->status_line, "\n";
}

How can I wait here until i get a file?
Thanks for hints and suggestions!
From: Ben Morrow on

Quoth cerr <ron.eggler(a)gmail.com>:
>
> I'm using libwww to post data to a form. Once data is posted, the
> server would send me back a file. How can i retrieve and safe this
> file?
> I'm posting the data with below code:
>
> $response = $browser->get($url);
> print $response->header('WWW-Authenticate'),"\n";
> die "Error at $url\n ", $response->status_line, "\n Aborting"
> unless $response->is_success;
> #print "Authentication successful! Got ",$response->content_type, "
> document!\n";
> # Create a post request
> my $post = HTTP::Request->new(POST => $PostPage);
> #print "Posting data to \"$PostPage\"\n";
> $post->content_type('application/x-www-form-urlencoded');
> $post->content('export_profile=Current%20Profile');
> # Pass request to the user agent and get a response back
> my $res = $browser->request($post);
>
> # Check the outcome of the response
> if ($res->is_success) {
> print $res->content , "\n";
> }
> else {
> print $res->status_line, "\n";
> }
>
> How can I wait here until i get a file?
> Thanks for hints and suggestions!

The file returned from the server should be in the $res object. See the
documentation for HTTP::Response.

Ben

From: cerr on
On Feb 22, 2:36 pm, Ben Morrow <b...(a)morrow.me.uk> wrote:
> Quoth cerr <ron.egg...(a)gmail.com>:
>
>
>
>
>
>
>
> > I'm using libwww to post data to a form. Once data is posted, the
> > server would send me back a file. How can i retrieve and safe this
> > file?
> > I'm posting the data with below code:
>
> >   $response = $browser->get($url);
> >   print $response->header('WWW-Authenticate'),"\n";
> >   die "Error at $url\n ", $response->status_line, "\n Aborting"
> >   unless $response->is_success;
> >   #print "Authentication successful!  Got ",$response->content_type, "
> > document!\n";
> >   # Create a post request
> >   my $post = HTTP::Request->new(POST => $PostPage);
> >   #print "Posting data to \"$PostPage\"\n";
> >   $post->content_type('application/x-www-form-urlencoded');
> >   $post->content('export_profile=Current%20Profile');
> >   # Pass request to the user agent and get a response back
> >   my $res = $browser->request($post);
>
> >   # Check the outcome of the response
> >   if ($res->is_success) {
> >       print $res->content , "\n";
> >   }
> >   else {
> >       print $res->status_line, "\n";
> >   }
>
> > How can I wait here until i get a file?
> > Thanks for hints and suggestions!
>
> The file returned from the server should be in the $res object. See the
> documentation for HTTP::Response.
>
Hi Ben,

Yep, been looking at that too but I haven't really gotten any further
unfortunately :( $res->filename e.g. is returning the filename of the
script i'm posting to but not the filename the server is sending back.
I don't know how i'd get the data. Been playing with
decoded_content('none') as well (cause the file coming back is in
binary) - but no success either - anymore hints maybe?

Thanks!

--
roN
From: Ben Morrow on

Quoth cerr <ron.eggler(a)gmail.com>:
> On Feb 22, 2:36�pm, Ben Morrow <b...(a)morrow.me.uk> wrote:
> >
> > The file returned from the server should be in the $res object. See the
> > documentation for HTTP::Response.
>
> Yep, been looking at that too but I haven't really gotten any further
> unfortunately :( $res->filename e.g. is returning the filename of the
> script i'm posting to but not the filename the server is sending back.
> I don't know how i'd get the data. Been playing with
> decoded_content('none') as well (cause the file coming back is in
> binary) - but no success either - anymore hints maybe?

The data is in ->content. If ->filename is returning the request URI,
then probably the server is not sending a Content-Disposition header
that specifies a filename. Can you post $res->headers->as_string?

Ben

From: cerr on
On Feb 22, 3:43 pm, Ben Morrow <b...(a)morrow.me.uk> wrote:
> Quoth cerr <ron.egg...(a)gmail.com>:
>
> > On Feb 22, 2:36 pm, Ben Morrow <b...(a)morrow.me.uk> wrote:
>
> > > The file returned from the server should be in the $res object. See the
> > > documentation for HTTP::Response.
>
> > Yep, been looking at that too but I haven't really gotten any further
> > unfortunately :( $res->filename e.g. is returning the filename of the
> > script i'm posting to but not the filename the server is sending back.
> > I don't know how i'd get the data. Been playing with
> > decoded_content('none') as well (cause the file coming back is in
> > binary) - but no success either - anymore hints maybe?
>
> The data is in ->content. If ->filename is returning the request URI,
> then probably the server is not sending a Content-Disposition header
> that specifies a filename. Can you post $res->headers->as_string?
>
For me it seems like content only returns the html of the page i just
submitted data from.
res->headers->as_string contains HTTP::Response=HASH(0x9e368b0)-
>headers->as_string...

hm, the html of the little form i would like to submit from looks like
this:
<form method="post" action="/cgi-bin/config.pl" enctype="application/x-
www-form-urlencoded" name="save">
<select name="export_profile">
<option selected="selected" value="Current Profile">Current Profile</
option>
<option value="Last Known Good Profile">Last Known Good Profile</
option>
<option value="Minimal Profile">Minimal Profile</option>
</select><input type="submit" name="save" value="Export" /></form>
and the POST string i assembled looks like:"export_profile=Current
%20Profile". I'm not sure if that's correct :( I don't know how i can
implement the form name "save" into my post string, do i need to do
that too?
Thanks!
--
roN