2011-07-01 4 views

답변

9

이 사용하는 소켓을 할 수

use LWP::UserAgent; 
$ua = LWP::UserAgent->new; 

$req = HTTP::Request->new(GET => 'http://www.example.org/index.html'); 
$req->header('Cookie' => 'test=quest'); 

# send request 
$res = $ua->request($req); 

# check the outcome 
if ($res->is_success) { print $res->decoded_content } 
else { print "Error: " . $res->status_line . "\n" } 

당신은에 대한 소개의 LWP cookbook을 읽는 시도 할 수 있습니다 LWP.

3

LWP::UserAgent은 일반 출발점입니다. 특정 쿠키 값을 미리 설정하려면 HTTP::Cookies 객체를 수동으로 전달할 수 있습니다. 대신

use IO::Socket; 
my $sock = new IO::Socket::INET (
           PeerAddr => 'www.example.org', 
           PeerPort => '80', 
           Proto => 'tcp', 
           ); 
die "Could not create socket: $!\n" unless $sock; 
print $sock "GET /index.html HTTP/1.0\r\n"; 
print $sock "Host: www.example.org\r\n"; 
print $sock "Cookie: test=quest\r\n\r\n"; 
print while <$sock>; 
close($sock); 

하지만 당신은 LWP (직접 libwww - 펄)를 사용하여 고려할 수 있습니다 :