Skip to content

Instantly share code, notes, and snippets.

@mchubby
Last active October 14, 2015 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchubby/8c91b29cdece0212b51d to your computer and use it in GitHub Desktop.
Save mchubby/8c91b29cdece0212b51d to your computer and use it in GitHub Desktop.
A tidbit showing how to get a YAML file for later parsing (place both pure-perl modules in a vendor/ subdir)
use warnings; use strict; use 5.010;
use File::Basename "dirname";
use lib dirname(__FILE__)."/vendor"; # modify @INC
use HTTP::Tiny;
use YAML::Tiny;
my ($username, ) = @ARGV;
die("ERR-Manque arg1 (username)") unless $username;
my $url = 'http://pastebin.com/raw.php?i=PYmvwsZ2';
# my $url = 'https://raw.githubusercontent.com/jedk1/WCMN/master/src/config.yml';
# $url = 'http://1.1.1.1/'; # test timeout
# $url = 'http://127.1.1.1/'; # test with a local TCP server
# set no_proxy to the target domain name, to bypass any env var
my $response = HTTP::Tiny->new( timeout => 15, no_proxy => 'pastebin.com',
agent => 'Script-Perl-HTTP-Tiny-20151014/1.0' )->get($url);
# si passage par la methode POST requis, capturer une requete d'envoi de
# formulaire avec les outils de developpement Firefox et la passer via
# l'appel a post_form()
#my $response = HTTP::Tiny->new->post_form($url,
# [
# "chkField1" => 1,
# "chkField2" => 0,
# ]
#);
say "URL: $url";
say "Success: ", $response->{success}? "true" : "false";
say "Status: $response->{status}";
say "Reason: $response->{reason}";
say 'Length: ', length $response->{content};
print $response->{content}, "\n";
if ($response->{success}) {
my $yaml = YAML::Tiny->new();
$yaml = YAML::Tiny->read_string($response->{content});
print $yaml->[0]->{Flag1}, "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment