On Sunday 14 November 2004 12:25, Zeus Odin wrote: > "Philipp Traeder" <[EMAIL PROTECTED]> wrote in message... > > > I guess LWP::UserAgent might be interesting in this context, but I > > wouldn't > > > try to parse the responses you get. Why don't you pass the resulting code > > through only? > > I imagine the resulting code you're referring to is more than a server > response of 200, 400, etc. Right?
Yep, I was thinking about the full HTTP response (including headers, HTML code etc.) > > > Something like (not tested, pseudo code only): > > > > #!/usr/bin/perl -w > > > > use strict; > > use CGI; > > use LWP::UserAgent; > > > > # let's say your script is called like this: > > # http://mysite.com/relay.pl?url=http://www.disney.com > > my $query = new CGI(); > > my $url_to_visit = $query->param('url'); > > Is $query used only to get the url parameter? In this script, yes - but thinking about it again, I guess you would need to do some things more. What you're writing is more or less a proxy: ---------- ---------- ---------- | client | --> | proxy | --> | server | ---------- ---------- ---------- The base idea behind this (as I see it - I've never worked with something like this, so be advised that I might talk complete nonsense here ;-) ) is that the client "thinks" he's talking with the proxy, but the proxy acts as intermediate, forwards all requests and executes them against the real server. Therefore, the code I sketched in the last posting is not enough by far - you've got to duplicate the whole request. Let's take a look at how a google query looks like: Request1) GET http://www.google.com The response is a simple HTML page with a button and an input field for the search string. Let's say the second request looks like this (just speculating - I'm too lazy to check how it looks like in details): Request2) GET http://www.google.com?query=the_input_from_the_text_field&action=search Let's ignore for a moment the problem that you need to tell your script against which site you want to connect - if we assume that it'll be google.com always, you could write a script like: # get all the request parameters that have been sent to us: my $query = new CGI(); my @names = $query->param(); # now we would need to convert them into a format that LWP::UserAgent can use foreach my $param_name (@names) { [...] } > > > my $ua = new LWP::UserAgent(); > > # you should use something more general than "GET" here...don't know the > > # syntax OTTOMH > > my $response = $ua -> get($url_to_visit); > > print $response; > > I would imagine I would have to interpret each web page click to determine > if a GET, POST, or running code is necessary. Yes, and each "web page click" is a request that is sent to your script - therefore you could decide whether to use GET or POST by taking a look at the method of the request your script has received - if the client sent you a GET, you need to send a GET etc. A first version shouldn't be too hard, but the details might become interesting - what about cookies, HTTP authentication, http headers, forwards/redirects etc? > > > I'm not sure, but this sounds more or less like something I read in the > > documentation of mod_proxy - maybe you want to take a look at > > > > http://httpd.apache.org/docs/mod/mod_proxy.html > > Thanks. I will take a look. This might be a good idea if you want to avoid headaches ;-) > > > Without having thought about it too much, there might be some > > security-related > > > concerns you might want to think about - if you implement something like > > this > > > accessible to the public, you allow everybody to visit web pages in a way > > that it looks like you/your server did it. What if somebody uses your > > "relay" > > > server to download MP3s illegally? > > This is not a web site I will advertise. I will allow only certain ip > addresses, so at most 5 people will use it. If they absuse it in any way, I > can just strangle them because I know them all. > > >:-) Then everything you need are good relations to the local cops - make them offers they can't refuse. ;-) HTH, Philipp -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>