Skip to content

Instantly share code, notes, and snippets.

@fukata
Created September 28, 2011 02:18
Show Gist options
  • Save fukata/1246825 to your computer and use it in GitHub Desktop.
Save fukata/1246825 to your computer and use it in GitHub Desktop.
Post file and data use LWP::UserAgent.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Encode;
use HTTP::Request::Common;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent('FUKATA/1.0 ');
my $data = {
name = '深田達也',
description = 'ニートになりたいプログラマ',
icon => ['/tmp/icon.png'],
};
$data->{$_} = Encode::encode('utf8', $data->{$_}) for qw/name description/;
my $post_url = 'http://localhost/dump.php';
my $res = $ua->request(POST(
$post_url,
Content_Type => 'form-data',
Content => $data,
));
print $res->content;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment