Browse Source

get token

nas 2 years ago
parent
commit
e62e8d57b2
1 changed files with 19 additions and 5 deletions
  1. 19
    5
      test/remote/test.pl

+ 19
- 5
test/remote/test.pl View File

11
 print "Username : $config{Authentification}{Username}\n";
11
 print "Username : $config{Authentification}{Username}\n";
12
 print "Host : $config{Authentification}{Host}\n";
12
 print "Host : $config{Authentification}{Host}\n";
13
 print "Host : $config{Authentification}{Path}\n";
13
 print "Host : $config{Authentification}{Path}\n";
14
-print "Protocol : $config{Authentification}{Username}\n";
14
+print "Protocol : $config{Authentification}{Protocol}\n";
15
 
15
 
16
-local $url = "$config{Authentification}{Host}$config{Authentification}{Path}";
16
+local $url = "$config{Authentification}{Protocol}$config{Authentification}{Host}$config{Authentification}{Path}";
17
 local $ua = LWP::UserAgent->new(timeout => 10);
17
 local $ua = LWP::UserAgent->new(timeout => 10);
18
 $ua->env_proxy;
18
 $ua->env_proxy;
19
 
19
 
20
-sub rq {
20
+sub get_code {
21
   my $path = (exists $_[0])? $_[0] : "";
21
   my $path = (exists $_[0])? $_[0] : "";
22
   my $response = $ua->get( "$url$path" );
22
   my $response = $ua->get( "$url$path" );
23
   print "rq $url$path\n";
23
   print "rq $url$path\n";
31
   }
31
   }
32
 }
32
 }
33
 
33
 
34
-rq();
35
-rq( "tokens" );
34
+get_code();
35
+get_code( "tokens" );
36
+
37
+sub rq {
38
+  my $path = (exists $_[0])? $_[0] : "";
39
+  my $method = (exists $_[1])? $_[1] : "";
40
+  my $content = (exists $_[2])? $_[2] : "";
41
+
42
+  my $req = HTTP::Request->new(POST => "$url$path");
43
+  $req->content_type('application/json');
44
+  $req->content("$content");
45
+  my $res = $ua->request($req);
46
+  print $res->as_string;
47
+}
48
+
49
+rq( "tokens", "GET", "{\"user\" : {\"email\" : \"$config{Authentification}{Email}\", \"password\" : \"$config{Authentification}{Password}\"}}" );

Loading…
Cancel
Save