Skip to content

Commit 07dd823

Browse files
committed
Add POST example and tweak GET example
1 parent 77bbac3 commit 07dd823

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

eg/get.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
}
1818
}
1919

20-
print $response->{content} if defined $response->{content};
20+
print $response->{content} if length $response->{content};
2121

eg/post.pl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
6+
use HTTP::Tiny;
7+
use URI::Escape qw/uri_escape_utf8/;
8+
9+
my $url = 'http://search.cpan.org/search';
10+
11+
my %form_data = (
12+
query => 'DAGOLDEN',
13+
mode => 'author',
14+
);
15+
16+
my @params;
17+
while( my @pair = each %form_data ) {
18+
push @params, join("=", map { uri_escape_utf8($_) } @pair);
19+
}
20+
21+
my $response = HTTP::Tiny->new->request('POST', $url, {
22+
content => join("&", @params),
23+
headers => { 'content-type' => 'application/x-www-form-urlencoded' }
24+
});
25+
26+
print "$response->{status} $response->{reason}\n";
27+
28+
print $response->{content};
29+

0 commit comments

Comments
 (0)