Last active
October 14, 2015 09:15
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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