How to POST content with an HTTP Request (Perl)

前端 未结 2 540
旧巷少年郎
旧巷少年郎 2021-02-08 03:53
use LWP::UserAgent;
use Data::Dumper;

my $ua = new LWP::UserAgent;
$ua->agent(\"AgentName/0.1 \" . $ua->agent);
my $req = new HTTP::Request POST => \'http://ex         


        
2条回答
  •  失恋的感觉
    2021-02-08 04:35

    The answer given didn't work for me. I still had the same problem as OP.

    The documentation for LWP::UserAgent wants a hash or array reference.

    This works:

    my $url = 'https://www.google.com/recaptcha/api/siteverify';
    my $ua      = LWP::UserAgent->new(); 
    
    my %form;
    $form{'secret'}='xxxxxxxxxxxxxxxxxxxxxxx';
    $form{'response'}=$captchaResponse;
    
    my $response = $ua->post( $url, \%form ); 
    my $content = $response->as_string();
    

提交回复
热议问题