Re: HTTP::Request
On Friday, Nov 7, 2003, at 17:12 US/Pacific, Tobias Fink wrote: [..] but what i didnt want to do is something like this: my $response = $ua-get(http://search.cpan.org/ search?query=$queryquery2=$query2etc); because this only works for http-get. Isnt it possible to create a header that works with get and post? [..] tobias, remember the differences between a 'GET' and a 'POST'. A 'GET' passes all that it knows in the URI itself, as in the case above. The POST will pass the 'path' portion of the URI to the web-server, and send the 'query' itself as a part of the 'body' of the message. hence the post will send the URI http://search.cpan.org/search; and then woof the query string as content. I have two handy dandy little subs squirrelled away that help me remember this: # # sub form_GET_msg($$) { my ($host_port, $url) = @_; my $msg = GET $url HTTP/1.1 . $CRLF . Host: $host_port . $CRLF . $CRLF ; return($msg); } # end of form_GET_msg # # sub form_Post_msg($$$) { my ($dtk_host_port, $dtk_url , $string) = @_; my $len = length($string); my $msg = POST $dtk_url HTTP/1.1 . $CRLF . Host: $dtk_host_port . $CRLF . Content-Type: application/x-www-form-urlencoded . $CRLF . Content-Length: $len . $CRLF . $CRLF . $string; } # end of form_Post_msg so there really is no 'simple' way to make them 'universal'. So if you really want to get down into the mud and write your own munger to strip the URI into it's component parts schema:://host_port/path and sort out say your 'query' as a hash then you can do the sort of trick like: ... dtk_openSocket_to_webPage( $host, $port, $fd); my $message = ($query_hash)? form_Post_msg($host_port, $uri, http_url_packer($query_hash)) : form_GET_msg($host_port, $uri); $fd-print($message); my ($status, $headers) = dtk_get_headers($fd); ... and I will be so behind you in that part of the Learning Process. { he said noting the shrapnel that makes me look like a pin cushion I encountered on that learning curve, knowing full well that it will be ever so nice to have someone ELSE 'up front' 8-) } Oh dear, that is some old and crufty code, should I be showing it in public with all of it's warts??? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: HTTP::Request
Hi, thanks for all your help :) but what i didnt want to do is something like this: my $response = $ua-get(http://search.cpan.org/search?query=$queryquery2=$query2etc;); because this only works for http-get. Isnt it possible to create a header that works with get and post? Greetings, Tobias - Original Message - From: Sara [EMAIL PROTECTED] To: Tobias Fink [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, November 06, 2003 10:07 AM Subject: Re: HTTP::Request #!/usr/bin/perl use CGI; use LWP::UserAgent; my $q = new CGI; my $query = $q-param('query') || 'LWP'; use LWP::UserAgent; my $ua = LWP::UserAgent-new; my $response = $ua-get(http://search.cpan.org/search?query=$query;); if ($response-is_success) { my $server_response = $response-content; print $server_response; } - Original Message - From: Tobias Fink [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, November 07, 2003 4:12 AM Subject: HTTP::Request Hi, why doesn't my $ua = LWP::UserAgent-new; my $res = $ua-request(GET 'http://www.google.de/search', q = 'asdasd'); if ($res-is_success) { my $server_response = $res-content; print $server_response; } print the html-source of http://www.google.de/search?q=asdasd ? Regards, Tobias -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
HTTP::Request
Hi, why doesn't my $ua = LWP::UserAgent-new; my $res = $ua-request(GET 'http://www.google.de/search', q = 'asdasd'); if ($res-is_success) { my $server_response = $res-content; print $server_response; } print the html-source of http://www.google.de/search?q=asdasd ? Regards, Tobias -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: HTTP::Request
Tobias Fink wrote: Hi, why doesn't my $ua = LWP::UserAgent-new; my $res = $ua-request(GET 'http://www.google.de/search', q = 'asdasd'); if ($res-is_success) { my $server_response = $res-content; print $server_response; } print the html-source of http://www.google.de/search?q=asdasd ? It has a syntax error. Or is this not your real code? Among other problems. perldoc LWP::UserAgent http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: HTTP::Request
On Thursday, Nov 6, 2003, at 15:12 US/Pacific, Tobias Fink wrote: [..] why doesn't my $ua = LWP::UserAgent-new; my $res = $ua-request(GET 'http://www.google.de/search', q = 'asdasd'); if ($res-is_success) { my $server_response = $res-content; print $server_response; } print the html-source of http://www.google.de/search?q=asdasd ? well there seems to be a series of issues, not the least of which is that when I try the simple command line routine with the lwp-request code I get a 'forbidden' response back from www.google.com - so even IF I can put the string http://www.google.com/search?q=asdasd into a browser, the simple request [jeeves: 13:] lwp-request 'http://www.google.com/search?q=asdasd' HTML HEADTITLEAn Error Occurred/TITLE/HEAD BODY H1An Error Occurred/H1 403 Forbidden /BODY /HTML [jeeves: 14:] suggest that they may have 'issues' with web-bots. which you would notice with say code like: my $res = $ua-get('http://www.google.com/search?q=asdasd'); if ($res-is_success) { my $server_response = $res-content; print $server_response; } else { print request failed\n; print $res-content ; } At which point let us go back and look at the problem with your line my $res = $ua-request(GET 'http://www.google.de/search', q = 'asdasd'); sorry, but that just does NOT make sense to me. I can see what you were trying to do, but that is way garbled. IF you know what your query should be, then why not append it to the base 'uri' that you have if you will go back to perldoc LWP::UserAgent you will note that the more classical form, if you do not want to do the 'get()' method is to construct the HTTP::Request object, ( cf HTTP::Request ) and pass that object: $request = HTTP::Request-new('GET', 'http://search.cpan.org/'); # and then one of these: $response = $ua-request($request); so yes, the line is broken, but there also seems to be an interesting server side issue that google has with web-bots. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: help with HTTP::Request for POST
on di, 18 feb 2003 16:43:22 GMT, Scott Lutz wrote: What I am attempting to do, is do a server side form action redirect based on a regex on a field from the form. It now seems that this is just going to POST the form data, and leave the user hanging. Is HTTP::Request the best way to direct the user and the form data to the appropriate page? This is a vary slightly modified version of the example in the docs, and yet it returns no more data than this in my log, though the script is chmod'd 755 : [Mon Feb 17 17:04:05 2003] [error] [client 66.51.160.131] Premature end of script headers: /var/cgi-bin/parse.cgi Any help with what might be missing would be great You are *still* not producing any output... -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: help with HTTP::Request for POST
On Tuesday, Feb 18, 2003, at 08:43 US/Pacific, Scott Lutz wrote: What I am attempting to do, is do a server side form action redirect based on a regex on a field from the form. [..] [Mon Feb 17 17:04:05 2003] [error] [client 66.51.160.131] Premature end of script headers: /var/cgi-bin/parse.cgi Any help with what might be missing would be great Here is the script: #!/usr/bin/perl -wT use strict; use HTTP::Request::Common; use LWP::UserAgent; use CGI; use CGI::Carp qw(fatalsToBrowser); my $q = new CGI; my $ua = LWP::UserAgent-new; if ($q-param(domain) =~ /\.ca$/) { $ua-request(POST 'https://domains/perl/ca_reg.cgi', [ domain = $q-param(domain), affiliate_id = $q-param(affiliate_id), action = $q-param(lookup), ]); } else { $ua-request(POST 'https://domains/perl/reg_system.cgi', [ domain = $q-param(domain), affiliate_id = $q-param(affiliate_id), action = $q-param(lookup), ]); } Please do not hesitate to contact me directly if you have any more questions! assuming that the above is your script there is the minor problem that it is not sending anything back to the browser which is the 'exit prematurely' argument what you will want to do is send a redirect back to the browser to query the other scripts... the other alternative is to use a piece of javascripting that will resolve this on the client side before sending a request back to the server. you can think of this in terms of say my @targets = qw(ca_reg.cgi ca_system.cgi); my $index = 0; my $jscript = 'script language=JavaScript type=text/javascript !-- function doit(){ var base_uri = https://domains/perl/;; var urls=new Array();' .\n;' foreach my $targ (@targets) { $jscript .= 'urls[' . $index++ . ']=' . $targ . \;\n; } $jscript .= 'var nChosen = document.FormName.sysname.selectedIndex; var wordup = base_uri + urls[nChosen]; document.FormName.action= wordup; document.FormName.method = POST; return true; } //-- /SCRIPT'; my $form = 'form name=FormName action=../ onsubmit=doit() target=_top' # # the part where you stuff in the 'hidden values' you want, # such as the domain,affiliate_id, etc... or put them in # other things that this 'form' would send back # .. If you put that '$jscript' into the head.../head and show your 'form' in the body.../body when you user 'submits' it will go through the 'javascript' to resolve the 'real method' and sent the Post to the two scripts. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: help with HTTP::Request for POST
On Tuesday, Feb 18, 2003, at 10:33 US/Pacific, Scott Lutz wrote: [..] Thanks for the input drieux! All of the information that I have found has said that you can not change the form action using IE, which is why I was led to the server side method. I will try the javascript, to see how it works! [..] If you really want to go with the server side push, then you will need to do something on the order of: # # stuff that resolves the uri into the form of a GET # print Content-Type: $type . $CRLF . Location: $uri . $CRLF . $CRLF; but I have not figured a way to get that to tell the browser to relocate to the $uri and retransmit the POST data along - have tried a few tricks, none of them worked out. the javascript idea was proposed here a while back, and I was hoping for what you are hoping for, but also it is not really an IE problem, unless it is a problem in pre-IE5 versions, but I do not have any versions of IE prior to 5.2 for Mac... But I can say that the trick I sent you is based upon code I have that works with IE5/IE6(win), Netscape 4, Netscape 6/7 Omniweb, Some times spinning up the javascripting IS the trick. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: help with HTTP::Request for POST
Thanks for the input drieux! All of the information that I have found has said that you can not change the form action using IE, which is why I was led to the server side method. I will try the javascript, to see how it works! Scott Lutz Pacific Online Support Phone: 604.638.6010 Fax: 604.638.6020 Toll Free: 1.877.503.9870 http://www.pacificonline.com -Original Message- From: drieux [mailto:[EMAIL PROTECTED]] Sent: February 18, 2003 10:02 AM To: Scott Lutz Cc: cgi cgi-list Subject: Re: help with HTTP::Request for POST On Tuesday, Feb 18, 2003, at 08:43 US/Pacific, Scott Lutz wrote: What I am attempting to do, is do a server side form action redirect based on a regex on a field from the form. [..] [Mon Feb 17 17:04:05 2003] [error] [client 66.51.160.131] Premature end of script headers: /var/cgi-bin/parse.cgi Any help with what might be missing would be great Here is the script: #!/usr/bin/perl -wT use strict; use HTTP::Request::Common; use LWP::UserAgent; use CGI; use CGI::Carp qw(fatalsToBrowser); my $q = new CGI; my $ua = LWP::UserAgent-new; if ($q-param(domain) =~ /\.ca$/) { $ua-request(POST 'https://domains/perl/ca_reg.cgi', [ domain = $q-param(domain), affiliate_id = $q-param(affiliate_id), action = $q-param(lookup), ]); } else { $ua-request(POST 'https://domains/perl/reg_system.cgi', [ domain = $q-param(domain), affiliate_id = $q-param(affiliate_id), action = $q-param(lookup), ]); } Please do not hesitate to contact me directly if you have any more questions! assuming that the above is your script there is the minor problem that it is not sending anything back to the browser which is the 'exit prematurely' argument what you will want to do is send a redirect back to the browser to query the other scripts... the other alternative is to use a piece of javascripting that will resolve this on the client side before sending a request back to the server. you can think of this in terms of say my @targets = qw(ca_reg.cgi ca_system.cgi); my $index = 0; my $jscript = 'script language=JavaScript type=text/javascript !-- function doit(){ var base_uri = https://domains/perl/;; var urls=new Array();' .\n;' foreach my $targ (@targets) { $jscript .= 'urls[' . $index++ . ']=' . $targ . \;\n; } $jscript .= 'var nChosen = document.FormName.sysname.selectedIndex; var wordup = base_uri + urls[nChosen]; document.FormName.action= wordup; document.FormName.method = POST; return true; } //-- /SCRIPT'; my $form = 'form name=FormName action=../ onsubmit=doit() target=_top' # # the part where you stuff in the 'hidden values' you want, # such as the domain,affiliate_id, etc... or put them in # other things that this 'form' would send back # .. If you put that '$jscript' into the head.../head and show your 'form' in the body.../body when you user 'submits' it will go through the 'javascript' to resolve the 'real method' and sent the Post to the two scripts. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
HTTP request error 500
hi everyone... I guess this problem is less related to perl (though it might be) and more related to HTTP... I'm trying to write a program that sends an HTTP request (using LWP::UserAgent::Request) to a server (web.icq.com, which i know is working fine), but all i get in status_line is 500 Can't connect to web.icq.com:80 (Timeout). is this some problem with the server? (it's not my server, it's one of those free web hosting ones...) any ideas? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]