Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: [ANNOUNCE] fahrplan.pl - get up-to-date traintimetables(for Germany)



On Sun, 5 Sep 2004, Achim Tuffentsammer (AT) wrote:

AT> Sergei Haller wrote:
AT> 
AT> > is it possible to pass a proxy server name, user name and password to that
AT> > routines?
AT> > 

AT> Have a look at http://www.perldoc.com/perl5.6/lib/lwpcook.html#PROXIES

actually, this was more a feature request than a question for how to do it 
myself ;-)

but inspired by Achims link, I just done this myself, here is the patch:

-------------------------------------------------------------------------
--- fahrplan.pl.orig    2004-09-03 01:04:06.000000000 +1000
+++ fahrplan.pl 2004-09-06 00:39:37.000000000 +1000
@@ -33,6 +33,14 @@
 use warnings;
 use LWP::UserAgent;

+#
+# If you have to use a proxy, set it here. Keep in mind
+# that putting passwords into scripts is actually a bad idea...
+#
+my $PROXY_HOST = '';
+my $PROXY_USER = '';
+my $PROXY_PASS = '';
+
 my $SHOW_TICKER = 1;                                                           
# Newsticker abfragen (fr Mnchen)

 my $BAHNHOF = $ARGV[0] || die "Syntax: $0 Bahnhof-ID";
@@ -66,7 +74,12 @@
                agent   => "RIS4VDR",
                timeout => $timeout
        );
-       my $response = $ua->get($url);
+     my $req = HTTP::Request->new('GET',$url);
+     if ($PROXY_HOST ne '') {
+          $ua->proxy(http  => $PROXY_HOST);
+          $req->proxy_authorization_basic($PROXY_USER, $PROXY_PASS);
+     }
+     my $response = $ua->request($req);
        if(!$response->is_success()) {
                $$content = $response->status_line;
                return 0;
-------------------------------------------------------------------------

(everything between the two --- lines)

Robert, could you add this feature to your script? thanks.
I can't try it here without a proxy, but it should work.


c ya
        Sergei
-- 
--------------------------------------------------------------------  -?)
         eMail:       Sergei.Haller@math.uni-giessen.de               /\\
-------------------------------------------------------------------- _\_V
Be careful of reading health books, you might die of a misprint.
                -- Mark Twain




Home | Main Index | Thread Index