File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ use strict;
2
+ use warnings;
3
+ use HTTP::Tiny;
4
+ use HTTP::CookieJar;
5
+
6
+ # Create a new HTTP::Tiny object
7
+ my $http = HTTP::Tiny-> new( cookie_jar => HTTP::CookieJar-> new );
8
+
9
+ # Define the URL to request
10
+ my $url = ' http://www.test.com' ;
11
+
12
+ # Perform a GET request
13
+ my $response = $http -> get($url );
14
+
15
+ # Check if the request was successful
16
+ if ( $response -> {success } ) {
17
+ print " Response Status: $response ->{status}\n " ;
18
+ print " Response Content:\n $response ->{content}\n " ;
19
+ }
20
+ else {
21
+ warn " Failed to get $url : $response ->{status} $response ->{reason}\n " ;
22
+ }
23
+
24
+ # Access the cookie jar
25
+ my $cookie_jar = $http -> {cookie_jar };
26
+
27
+ # Print cookies for the domain
28
+ my $cookies = $cookie_jar -> cookies_for($url );
29
+ if ($cookies ) {
30
+ print " Cookies:\n " ;
31
+ foreach my $cookie ( keys %$cookies ) {
32
+ print " $cookie : $cookies ->{$cookie }\n " ;
33
+ }
34
+ }
35
+ else {
36
+ print " No cookies\n " ;
37
+ }
You can’t perform that action at this time.
0 commit comments