Hi All,
I am trying to get the data I am requesting from the REST API to return the data in json format instead of XML. I found a small example in the documentatin, but I am unclear how to incorporate this into my code.
Any tips or advice would be greatly appreciated.
The example code:
#!/usr/bin/perl
use warnings;
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
my $message = '<?xml version="1.0" encoding="UTF-8"?>
<rs:model-request throttlesize="10"
xmlns:rs="http://www.ca.com/spectrum/restful/schema/request"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd ">
<rs:target-models>
<rs:models-search>
<rs:search-criteria xmlns="http://www.ca.com/spectrum/restful/schema/filter">
<devices-only-search />
<filtered-models>
<equals>
<attribute id="0x10009">
<value>NetEngOnline</value>
</attribute>
</equals>
</filtered-models>
</rs:search-criteria>
</rs:models-search>
</rs:target-models>
<!--
Hostname
IP Address
Security String
Model Type Name
-->
<rs:requested-attribute id="0x1006e" />
<rs:requested-attribute id="0x12d7f" />
<rs:requested-attribute id="0x10009" />
<rs:requested-attribute id="0x10000" />
</rs:model-request>';
#print $message;
my $req = new HTTP::Request 'POST','http://myspectrumserver.com:8080/spectrum/restful/models';
$req->content_type('application/xml');
$req->content($message);
$req->authorization_basic('username', 'password');
my $res = $ua->request($req);
print $res->as_string;