kleinbiker7 has asked for the wisdom of the Perl Monks concerning the following question:

Hey guys, I am not very familiar with URL encoding, and could do with some help here! Basically, I need to take a massive GET string (one that the server will reject) and transform it into a GET string with the proper length, so that it will be accepted.

Then it will be decoded. What is a simple way to do this, so that we can pass huge query strings to the server?

Thanks!

  • Comment on How do I shorten/encode huge GET strings?

Replies are listed 'Best First'.
Re: How do I shorten/encode huge GET strings?
by duff (Parson) on May 21, 2004 at 18:28 UTC
    Must you use GET? POST is better suited for large submissions.

    And what makes your QUERY_STRING so large? Do you have lots of name=value pairs that aren't used or have nothing as a value?

Re: How do I shorten/encode huge GET strings?
by Wonko the sane (Curate) on May 21, 2004 at 18:33 UTC
    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

      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

      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.