How can I make a JSON POST request with LWP?

后端 未结 4 1786
说谎
说谎 2020-12-12 21:03

If you try to login at https://orbit.theplanet.com/Login.aspx?url=/Default.aspx (use any username/password combination), you can see that the login credentials are sent as a

4条回答
  •  再見小時候
    2020-12-12 21:52

    You'll need to construct the HTTP request manually and pass that to LWP. Something like the following should do it:

    my $uri = 'https://orbit.theplanet.com/Login.aspx?url=/Default.aspx';
    my $json = '{"username":"foo","password":"bar"}';
    my $req = HTTP::Request->new( 'POST', $uri );
    $req->header( 'Content-Type' => 'application/json' );
    $req->content( $json );
    

    Then you can execute the request with LWP:

    my $lwp = LWP::UserAgent->new;
    $lwp->request( $req );
    

提交回复
热议问题