How can I make a JSON POST request with LWP?

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 );

Leave a Comment