Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

[LWP::UserAgent] Send POST request and ignore response

by Gangabass (Vicar)
on May 10, 2008 at 13:26 UTC ( [id://685869]=perlquestion: print w/replies, xml ) Need Help??

Gangabass has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I need to post a big list of networks into admin section of some website. And i use LWP::UserAgent for this.

$req = HTTP::Request->new( POST => "http://www.somesite.com/in +dex.php?admin/networks" ); $req->content_type('application/x-www-form-urlencoded'); $req->content("name=$name&address=$address&zip=$zip&savenetwor +k=Save+Network"); $res = $ua->request($req);

But then i post one network i get list of all inserted network in the response web page. And more data i insert then more data i recieve as response. So i have small request and big (1+ Mb) response.

So my question is: is there a way to POST data and ignore response?

Replies are listed 'Best First'.
Re: [LWP::UserAgent] Send POST request and ignore response
by ikegami (Patriarch) on May 10, 2008 at 15:03 UTC

    Off topic, here's a better way to create your request:

    use HTTP::Request::Common qw( POST ); $req = POST 'http://www.somesite.com/index.php?admin/networks', [ name => $name, address => $address, zip => $zip, savenetwork => 'Save Network', ];

    It creates an HTTP::Request object as before. The advantages is that it handles encoding for you and it's easier to read.

Re: [LWP::UserAgent] Send POST request and ignore response
by rhesa (Vicar) on May 10, 2008 at 14:16 UTC
    Set the chunk size to a low value, and add a callback to the request that dies immediately. That will abort the response after the first chunk has been read.

    Example:

    # read response in chunks of 10 bytes, with a callback function # that dies when receiving the first chunk. This aborts reception # of the entire response. $ua->request( $req, sub { die }, 10 );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://685869]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found