Posted By

bcmoney on 12/10/10


Tagged

http perl proxy


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wirenaught


Proxy.pl


 / Published in: Perl
 

URL: http://bcmoney-mobiletv.com/blog/2009/05/01/the-server-side-proxy/

Source for handling HTTP requests easily in Perl: http://stackoverflow.com/questions/134858/whats-the-simplest-way-to-make-a-http-get-request-in-perl

Work with N.Y.Times JSON API in Perl/AJAX: http://notetodogself.blogspot.com/2009/02/using-jquery-with-nyt-json-api.html

Handling HTTP Requests in Perl: http://perl.active-venture.com/lib/HTTP/Request/Common.html

Perl CGI Module: http://www.gossland.com/course/cgi_module/index.html

How to read URL Parameters in Perl: http://www.webdeveloper.com/forum/showthread.php?p=842109

How to read command-line args in Perl: http://www.devdaily.com/perl/perl-command-line-arguments-read-args

  1. #UNIX
  2. #!/usr/bin/perl
  3. #WIN
  4. #!c:/Perl/perl
  5.  
  6. use LWP::Simple;
  7. use CGI;
  8.  
  9. $cl = $ARGV[0]; #command-line
  10. $qp = CGI::param('url'); #query parameter
  11.  
  12. #DEBUG: print('Query: ' . $qp . ' | Command-line: ' . $cl . "\n\n");
  13.  
  14. #default to some URL, try to use query parameter or command-line first
  15. $url = ( defined($qp) && !($qp eq '') && !($qp[0] eq NULL) ) ? $qp : ( defined($cl) && !($cl eq '') && !($cl eq NULL) ) ? $cl : "http://example.com";
  16.  
  17. my ($type, $length, $mod) = head($url);
  18. $content = get($url);
  19. die "Can't GET $url" if (! defined $content);
  20.  
  21. print "Content-type: ".$type."\n\n";
  22. print $content;

Report this snippet  

You need to login to post a comment.