I am a newbie here, I hope I am able to explain my issue properly... I have a html form that takes file name and location and cgi script processes this input. file will be something like: file.ext and location will be like /some/folder/ My issue is, when i try to parse the querystring, the & and / in the string get converted to amp; and %2F and when i am trying to print the arguments, its not working... here is the output:
testjarName=some.jar&loc=some%2Ffolder&host=r9_7079&action=PatchjarName
some.jar some.jar
amp;loc
some some
amp;host
r9_7079 r9_7079
amp;action
Patch Patch
FILE IS some.jar and LOCAITON IS
file is some.jar
location some
machine is r9_7079
action is Patch
You typed:
Can someone please help? i have tried the param() call too, but no help. Form input method is GET Here is the script i am using:
#!/usr/local/bin/perl
use CGI qw(:standard);
#print header;
#print start_html('A Simple Example'),
$my_input = $ENV{QUERY_STRING};
print "Content-type: text/html\n\n";
print "";
print "<html><head></title>test</title></head><body>";
print "$ENV{QUERY_STRING}";
@fv_pairs = split /\&/ , $my_input;
foreach $pair (@fv_pairs) {
if($pair=~m/([^=]+)=(.*)/) {
$field = $1;
print "$field";
print "<br>";
$value = $2;
print "$value " ;
$value =~ s/\+/ /g;
print "$value " ;
print "<br>";
$value =~ s/%([\dA-Fa-f]{2})/pack("C", hex($1))/eg;
$INPUT{$field}=$value;
}
}
print "<br><hr>"; print "FILE IS $INPUT{jarName} and LOCAITON IS $INPUT{loc}";
if (param()) {
print "<hr>";
print
"file is ",em(param('jarName')),
p,
"location ",em(join(", ",param('loc'))),
p,
"machine is ",em(param('host')),
p,
"action is ",em(param('action')),
hr;
print "You typed: " . $input{'loc'} . "\n";
}
print "</body></html>";
#print end_html;
Please help. Thanks in advance.
Use HTML::Entities to encode / decode input strings. ( How can I decode HTML entities? )
param
will break up the query string and decode HTML characters for you:
perl -e 'use CGI qw(:standard);
print param("loc");
' 'testjarName=some.jar&loc=some%2Ffolder&host=r9_7079&action=PatchjarName'
Output:
some/folder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.