bssanchez93

HTTP Methods

Sep 19th, 2014
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.95 KB | None | 0 0
  1.     use warnings;
  2.     use strict;
  3.      
  4.     use LWP::UserAgent;
  5.     use HTTP::Request;
  6.      
  7.     my $lol = 0;
  8.     my $mtd = 0;
  9.     my $menu = 0;
  10.     my $url = "";
  11.     my $peti;
  12.     my $resp;
  13.      
  14.     sub menu
  15.     {
  16.         if($menu == 0)
  17.         {
  18.             print "Metodo de peticion disponibles: ";
  19.             print "\n [1] GET";
  20.             print "\n [2] POST";
  21.             print "\n [3] PUT";
  22.             print "\nElije [1-3]: ";
  23.             $menu = 1;        
  24.         }
  25.         $mtd = <STDIN>;
  26.        
  27.         if(!($mtd =~ /[1-3]/))
  28.         {
  29.             print "[X] Error, debes elegir un numero de 1 a 3: ";
  30.             &menu;
  31.         }
  32.     }
  33.      
  34.     sub url
  35.     {
  36.         print "URL: ";
  37.         $url = <STDIN>;
  38.         if(!($url =~ /^http:\/\//))
  39.         {
  40.             $url = "http://".$url;
  41.         }
  42.     }
  43.      
  44.     sub type
  45.     {
  46.         if($mtd == 1)
  47.         {
  48.             $peti = HTTP::Request->new(GET => $url);  
  49.         }
  50.         elsif($mtd == 2)
  51.         {
  52.             $peti = HTTP::Request->new(POST => $url);
  53.         }
  54.         else
  55.         {
  56.             $peti = HTTP::Request->new(PUT => $url);
  57.         }
  58.     }
  59.      
  60.     sub conexion
  61.     {
  62.         print "\nEstableciendo conexion";
  63.         my $nav = LWP::UserAgent->new();
  64.         $nav->agent("Lolz 2.0.1 - Linux RedHat v1000");
  65.        
  66.         chomp $url;
  67.        
  68.         &type;
  69.        
  70.         $resp = $nav->request($peti);
  71.         $resp = $resp->content();
  72.        
  73.         print "\nRespuesta desde servidor: [[$url]]";
  74.         #print "\n\n".$resp;
  75.         $lol = 1;
  76.     }
  77.      
  78.     sub archivo
  79.     {
  80.         if($lol == 1)
  81.         {
  82.         print "\n\nEscribiendo datos en archivo...";
  83.         open(FILE, ">archivo");
  84.         print FILE $resp;
  85.         close FILE;
  86.         print "\n-_Fin_-";
  87.         }
  88.     }
  89.      
  90.     &menu;
  91.     sleep(1);
  92.     &url;&conexion;&archivo;
  93.      
  94.     print "\nBy kid_goth";
  95.     print "\n";
  96.     sleep(3);
Advertisement
Add Comment
Please, Sign In to add comment