File: post.pl

package info (click to toggle)
libhttp-tiny-perl 0.090-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 788 kB
  • sloc: perl: 3,124; makefile: 6
file content (29 lines) | stat: -rw-r--r-- 568 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/perl

use strict;
use warnings;

use HTTP::Tiny;
use URI::Escape qw/uri_escape_utf8/;

my $url = 'http://search.cpan.org/search';

my %form_data = (
  query => 'DAGOLDEN',
  mode => 'author',
);

my @params;
while( my @pair = each %form_data ) {
  push @params, join("=", map { uri_escape_utf8($_) } @pair);
}

my $response = HTTP::Tiny->new->request('POST', $url, {
  content => join("&", @params),
  headers => { 'content-type' => 'application/x-www-form-urlencoded' }
});

print "$response->{status} $response->{reason}\n";

print $response->{content};