post request with content length 0

2007-04-25 Thread Ulrich Wisser

Hi,

I have a small script trying to login into a website. Of course they use 
forms and cookies for that. Unfortunately does my code not work. If 
tried many approaches but without success. One thing I recognized is, 
that $ua-post() sends Content-length: 0 header with the request. 
Which I find quite strange. Please see my script and sample output below.


What do I do wrong?

Running on Linux, Perl 5.8.3, LWP 5.76.

Thanks

Ulrich


use LWP::UserAgent;
$ua = LWP::UserAgent-new;
$ua-agent(MyApp/0.1 );
my $res = $ua-post('http://search.cpan.org/search', (perl test2 
query='libwww-perl',mode='dist'));

print $res-request-as_string;
print;


Sample output:
POST http://search.cpan.org/search
User-Agent: MyApp/0.1 libwww-perl/5.76
Content-Length: 0
Content-Type: application/x-www-form-urlencoded
Mode: dist
Query: libwww-perl


Re: post request with content length 0

2007-04-25 Thread Philippe Bruhat (BooK)
Le mercredi 25 avril 2007 à 10:54, Ulrich Wisser écrivait:
 Hi,
 
 I have a small script trying to login into a website. Of course they use 
 forms and cookies for that. Unfortunately does my code not work. If 
 tried many approaches but without success. One thing I recognized is, 
 that $ua-post() sends Content-length: 0 header with the request. 
 Which I find quite strange. Please see my script and sample output below.
 
 What do I do wrong?

Your call to post() looks wrong:

 my $res = $ua-post('http://search.cpan.org/search', (perl test2 
 query='libwww-perl',mode='dist'));

The manual says:

$ua-post( $url, \%form )
$ua-post( $url, [EMAIL PROTECTED] )
$ua-post( $url, \%form, $field_name = $value, ... )

-- 
 Philippe BooK Bruhat

 There is no greater magic than knowing exactly who and what you are.
 (Moral from Groo #2 (Image))