Skip to content

Instantly share code, notes, and snippets.

@ytnobody
Created May 16, 2012 05:58
Show Gist options
  • Save ytnobody/2707892 to your computer and use it in GitHub Desktop.
Save ytnobody/2707892 to your computer and use it in GitHub Desktop.
LWP::UserAgentを使ってBasic認証+GETパラメータつきのリクエストを発行するサンプル
#
# LWP::UserAgentを使ってBasic認証+GETパラメータつきのリクエストを発行するサンプル
#
use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
use URI;
# URIオブジェクト作成
my $uri = URI->new('http://localhost:10080/priv/hoge.php');
$uri->query_form(foo => 'bar', piyo => 123);
# requestオブジェクトを作成
my $req = GET( $uri->as_string );
$req->authorization_basic('user', 'pass');
print "========== REQUEST ==========\n";
print $req->as_string;
# resposeオブジェクトを取得
my $ua = LWP::UserAgent->new;
my $res = $ua->request($req);
print "========== RESPONSE =========\n";
print $res->as_string;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment