Advertisement
Guest User

Untitled

a guest
Jul 20th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use WWW::Mechanize;
  4. use JSON qw/encode_json/;
  5.  
  6. my $username = 'test';
  7. my $password = 'test';
  8. my $url = 'http://localhost:9990/management';
  9. my $method = WWW::Mechanize->new(autocheck => 1);
  10. my $data = encode_json {"operation" => "read-attribute","name" => "server-state", "json.pretty" => 1};
  11.  
  12.  
  13. $method->add_header('Accept'=>'text/plain');
  14. $method->add_header('Content-Type'=>'application/json');
  15. $method->credentials("localhost:9990","ManagementRealm", $username=>$password);
  16. $method->post($url, content=>$data );
  17.  
  18. my $result = JSON::XS->new->allow_nonref->decode($method->content());
  19. print "$i - $result->{result}";
  20.  
  21.  
  22. [fspolti@my-laptop probes-temp]$ perl perl-probe.pl
  23. - running[
  24.  
  25.  
  26.  
  27. #!/usr/bin/perl
  28.  
  29. use WWW::Mechanize;
  30. use JSON qw/encode_json/;
  31.  
  32. my $username = 'test';
  33. my $password = 'test';
  34. my $url = 'http://localhost:9990/management';
  35. my $method = WWW::Mechanize->new(autocheck => 1);
  36. my $data = encode_json {"operation" => "read-attribute","name" => "server-state", "json.pretty" => 1};
  37.  
  38.  
  39. $method->add_header('Accept'=>'text/plain');
  40. $method->add_header('Content-Type'=>'application/json');
  41. $method->credentials("localhost:9990","ManagementRealm", $username=>$password);
  42.  
  43. for (my $i=0; $i<10; $i++) {
  44. $method->post($url, content=>$data );
  45. my $result = JSON::XS->new->allow_nonref->decode($method->content());
  46. print "$i - $result->{result}";
  47. }
  48.  
  49.  
  50. [fspolti@my-laptop probes-temp]$ perl perl-probe.pl
  51. Error POSTing http://localhost:9990/management: Unauthorized at perl-probe.pl line 18.
  52. 0 - running[f
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement