Hello,
I set 2 default headers using default_header() method and one of them is
"Content-Type" which is set to "application/json", but it looks that it is
overidden with "application/x-www-form-urlencoded" when doing a POST
request. Is this intentionally?
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->default_header( "Content-Type" => "application/json" );
$ua->default_header( Authorization => "Bearer TOKEN_STRING_HERE" );
my $res = $ua->post( "https://api.digitalocean.com/v2/domains", Content =>
'json here' );
print $res->request->as_string;
The result is:
POST https://api.digitalocean.com/v2/domains
Authorization: Bearer TOKEN_STRING_HERE
User-Agent: libwww-perl/6.13
Content-Length: 9
Content-Type: application/x-www-form-urlencoded
json here
If I set this header in the POST request then it is kept and it is used as
it should:
my $res = $ua->post(
"https://api.digitalocean.com/v2/domains",
content_type => 'application/json',
Content => 'json here',
);
print $res->request->as_string;
The result is:
POST https://api.digitalocean.com/v2/domains
Authorization: Bearer TOKEN_STRING_HERE
User-Agent: libwww-perl/6.13
Content-Length: 9
Content-Type: application/json
json here
If I define the Content-Type header with default_header() as in the first
example but do a GET request, then it is sent fine, it is not overidden.
Is there a way of defining the Content-Type header as default somewhere
without needing to specify it in each POST request?
I use Perl 5.14, and LWP 6.13.
--Octavian