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=$query&query2=$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]