|
@@ -11,13 +11,13 @@ read_config 'test.cfg' => my %config;
|
11
|
11
|
print "Username : $config{Authentification}{Username}\n";
|
12
|
12
|
print "Host : $config{Authentification}{Host}\n";
|
13
|
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
|
17
|
local $ua = LWP::UserAgent->new(timeout => 10);
|
18
|
18
|
$ua->env_proxy;
|
19
|
19
|
|
20
|
|
-sub rq {
|
|
20
|
+sub get_code {
|
21
|
21
|
my $path = (exists $_[0])? $_[0] : "";
|
22
|
22
|
my $response = $ua->get( "$url$path" );
|
23
|
23
|
print "rq $url$path\n";
|
|
@@ -31,5 +31,19 @@ sub rq {
|
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}\"}}" );
|