[PerlChina] LWP::UserAgent的使用问题

=?GB2312?B?hWSEXoVk?= wanliyou at gmail.com
Mon Aug 7 02:07:27 PDT 2006


Some proxies also require that you send it a username/password in order to
let requests through. You should be able to add the required header, with
something like this:
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->proxy(['http', 'ftp'] => 'http://username:password@proxy.myorg.com');
$req = HTTP::Request->new('GET',"http://www.perl.com");
$res = $ua->request($req);
print $res->decoded_content if $res->is_success;

Replace C<proxy.myorg.com>, C<username> and C<password> with something
suitable for your site.


ËäȻҲÊÇÕâôдµÄ£¬µ«»¹ÊÇÐв»Í¨£¬Can't locate object method "decoded_content" via package
"HTTP::Headers" at (eval 14)
 line 1.

On 8/7/06, …d„^…d <wanliyou at gmail.com> wrote:
>
> $ua->proxy(['http', 'ftp'] => 'http://username:password@proxy.myorg.com'
> <http://username:password@proxy.myorg.com%27/>);
>
> ÕâÖÖ·½·¨Ó¦¸ÃÊÇÐв»Í¨µÄ£¬¾ßÌåʵÏÖÓ¦¸ÃÊÇÓãº
>
> credentials($hostport,$realm,$name,$pass)
>
> ÆäËûµÄºÃÀí½â£¬$realmÔõô˵£¿
>
> "$realmÊÇrealm nameÊÇremote-ServerµÄuserÒªÇóÈÏÖ¤µÄÒ»¸ö¹Ø¼ü×Ö"
> µ«¾¿¾¹ÔõôÉèÄØ£¿
>
>
> On 8/7/06, …d„^…d <wanliyou at gmail.com> wrote:
> >
> > English DOC is enough.
> > Thanks a lot!
> >
> >
> > On 8/7/06, Qiang (James) Li < shijialee at gmail.com> wrote:
> >
> > > On 8/4/06, …d„^…d < wanliyou at gmail.com> wrote:
> > >
> > > ±¾Ïë½ØȡijÍøÕ¾Ò³ÃæµÄÊý¾Ý£¬µ«×ÜÊDz»ÐÐ
> > >
> > > ºóÏëµ½¿ÉÄÜÒªÉèproxy£¬ÓÚÊÇ¿´UserAgentµÄÎĵµ£¬·¢ÏÖ$ua->proxy¿ÉÒÔÉèÖõØÖ·£¬µ«ID£¬ÅÂsswordÑéÖ¤µÄ·½·¨ÊÇʲôÄØ£¿
> >
> > short answer:
> >      $ua->proxy(['http', 'ftp'] => 'http://username:password@proxy.myorg.com'
> > <http://username:password@proxy.myorg.com%27>);
> > long answer, read: perldoc lwpcook
> >
> > > ÁíÍ⣺$ua->credentials( $netloc, $realm, $uname, $pass );¾ßÌåÔõôÓÃÄØ£¿
> >
> > read:
> >    http://www.perlchina.org/archive/archive.php?action=archive&page=15
> > or lwpcook
> >
> > sorry, no chinese here and i am on 56k dial-up ;-0
> >
> > Qiang
> >
> > _______________________________________________
> > China-pm mailing list
> > China-pm at pm.org
> > http://mail.pm.org/mailman/listinfo/china-pm
> >
> >
> >
> > --
> > --==Best Regards From WanLi==--
> >
>
>
>
> --
> --==Best Regards From WanLi==--
>



-- 
--==Best Regards From WanLi==--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/china-pm/attachments/20060807/08e132b7/attachment.html 


More information about the China-pm mailing list