in reply to How to get current URL with Query String

I would have liked to use CGI::url ( -absolute => 1, -query_string => 1 ) but this returns the POSTed params instead of the Query String.

If I understood you correclty, you are processing a POST request with POST data and a query string and like to retrieve just the URL parameters. In that case the following should work for you:

#!/usr/bin/perl use strict; use warnings; use CGI; my $q = CGI->new(); sub url_query_string { my ($q) = @_; # get the names of all URL parameters my @params = grep { length($_) } $q->url_param; return (@params > 0 ? '?' : '').join('&',map { # $q->url_param returns unescaped values so we have to escape them # again sprintf("%s=%s",$_,CGI::escape($q->url_param($_))) } @params); } print $q->header('text/plain'), $q->url(-absolute => 1).url_query_string($q),"\n";

Testing it with curl (assuming the base URL is localhost:8080/cgi-bin/test.pl):

$ curl -d foo=bar localhost:8080/cgi-bin/test.pl
/cgi-bin/test.pl
$ curl -d foo=bar localhost:8080/cgi-bin/test.pl?msg=hello%20world
/cgi-bin/test.pl?msg=hello%20world

Hope that helps.