http://qs321.pair.com?node_id=11148206


in reply to content type in LWP::UserAgent

According to the documentation, this should work (and if I understand the output, it really does).
#!/usr/bin/perl use warnings; use strict; use LWP::UserAgent; use Cpanel::JSON::XS qw{ encode_json }; my $ua = 'LWP::UserAgent'->new(timeout => 1); my $response = $ua->post('https://httpbin.org/post', 'content-type' => 'application/json', Content => encode_json({key => 'value'})); print $response->decoded_content;

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: content type in LWP::UserAgent
by stevieb (Canon) on Nov 17, 2022 at 15:33 UTC

    I can unequivocally say that what choroba has there works properly. Here's an actual working example I just tested (with some name/data modifications):

    use warnings; use strict; use LWP::UserAgent; use JSON; my $ua = LWP::UserAgent->new; my $body_content = { token => 'NTE2M2Q3YmFmMGEzNjEzMGQyZmFmYmViNGEasdfmNzkzMTE3NzI3MWMz +MDhkZjliYWE3NTI1OTg1MDQwNjNlZg' }; my $resp = $ua->post( 'https://my.server.com', 'Content-Type' => 'application/json', 'Content' => encode_json $body_content ); print $resp->decoded_content;