Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How do I shorten/encode huge GET strings?

by Wonko the sane (Deacon)
on May 21, 2004 at 18:33 UTC ( #355420=note: print w/ replies, xml ) Need Help??


in reply to How do I shorten/encode huge GET strings?

Hello,

I am not sure what you mean by shortening the GET string. If you have alot of data, a POST may be better suited.

This is what I usually do when I need to encode a hash of data to use in a GET request though.

sub _url_encode_data { my ( $data ) = @_; my $post_string; foreach my $field ( keys %$data ) { next if ( $data->{$field} eq '' ); $data->{$field} =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",or +d($1))/eg; $post_string .= "$field=$data->{$field}&"; } return $post_string; } # END _url_encode_data
There may be a better way to do this(of course).

Hope that helps though.

Wonko


Comment on Re: How do I shorten/encode huge GET strings?
Download Code
Re: Re: How do I shorten/encode huge GET strings?
by kleinbiker7 (Sexton) on May 21, 2004 at 19:18 UTC
    Cheers Wonko...I will try that... By the way, how do you decode that string after you passed it to the server? Thanks!
      use the URI package.
      It will allow you to easily break apart (or assemble) any url including the query form with all special character sequences converted.
Re: Re: How do I shorten/encode huge GET strings?
by Anonymous Monk on May 22, 2004 at 03:26 UTC
Re: Re: How do I shorten/encode huge GET strings?
by Jenda (Abbot) on May 22, 2004 at 20:50 UTC

    There are several wheels for this on CPAN already

    use CGI::Enurl; $url = 'script.pl?' . enurl($hashref);

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://355420]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (13)
As of 2014-07-10 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (207 votes), past polls