Skip to content

Instantly share code, notes, and snippets.

@unwiredlabs
Last active August 29, 2015 13:57
Show Gist options
  • Save unwiredlabs/9543022 to your computer and use it in GitHub Desktop.
Save unwiredlabs/9543022 to your computer and use it in GitHub Desktop.
Perl APIv2 example
#!/usr/local/bin/perl -w
#===================================================
# Program Name: unwiredlabs_perl_example.pl
# Author: Eitan Keren (eitan.keren@gmail.com)
# Description: send HTTP POST JSON format request using LWP
#===================================================
use strict;
use LWP::UserAgent;
my $uri = 'http://us1.unwiredlabs.com/v2/process.php';
my $json = qq(
\{
\"token\": "XXXXXX",\n
\"radio\": \"gsm\",\n
\"mcc\": 310,\n
\"mnc\": 410,\n
\"cells\": [{\n
\"lac\": 7033,\n
\"cid\": 17811\n
\}\]\n
\}\n
);
my $ua = LWP::UserAgent->new(env_proxy => 1, keep_alive => 1, timeout => 10, agent => 'Mozilla/5.0',);
my $req = new HTTP::Request POST => "$uri";
$req->header( 'Content-Type' => 'application/json' );
$req->content( $json );
my $res = $ua->request($req);
print ("====\n" . $res->as_string . "\n====\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment