1

I'm trying to execute a API using a perl script. I'm in initial stage and below is the simple script I got which is not working. I have used get command to execute the API. But I'm not sure it will work or not. In fact I'm not able to find the get command will work not because I'm getting a different error in this code . This script gives me error like below

Use of uninitialized value $api_content in print at igmp.pl line 11.

Here is the script.

#!/usr/bin/perl   
use strict; 
use warnings;  
use LWP::Simple;  

my $api_content;

my $api = 'https://admin:[email protected]/set_param?init.snmp_ver=3&mib.save'; 
$api_content = get($api); 

print $api_content;

Please let me know if there is a command is will be useful for executing this simple API. Basically I need to set the value of snmp to 3 and save.

1 Answer 1

2

I think your problem is, that you need to use LWP::UserAgent directly so you can see the details of the response:

my $ua = LWP::UserAgent->new;
my $response = $ua->get('https://admin:[email protected]/set_param?init.snmp_ver=3&mib.save');

if ($response->is_success) {
    print $response->decoded_content;  # or whatever
}
else {
    die $response->status_line;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.