How to POST content with an HTTP Request (Perl)

前端 未结 2 539
旧巷少年郎
旧巷少年郎 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();
    
    0 讨论(0)
  • 2021-02-08 04:46
    my $ua      = LWP::UserAgent->new(); 
    my $request = POST( $url, [ 'port' => 8, 'target' => 64 ] ); 
    my $content = $ua->request($request)->as_string(); 
    
    0 讨论(0)
提交回复
热议问题