Connecting Tech Pros Worldwide Help | Site Map

Cannot get the korean value that was posted to CGI

Newbie
 
Join Date: Nov 2006
Posts: 4
#1: Nov 12 '06
CASE-1: From a CGI window, when I open another CGI window using window.open() and post a korean value [ encoded using Javascript encodeURI() ] through the URL, and then if I read the input using PERL from
STDIN, I dont receive the original Korean string. I see some junk content.

CASE-2: On the other side, if I post the Korean value [ encoded with EUC_KR ] using Java to the same CGI window, I could get my original Korean string from the PERL STDIN. In this case, I am before posting
it to the CGI.

For the both the above cases the web server used is Apache (2.0.54)
Is there any way to resolve CASE-1?
Newbie
 
Join Date: Nov 2006
Posts: 4
#2: Nov 12 '06

re: Cannot get the korean value that was posted to CGI


CASE-1: From a CGI window, when I open another CGI window using window.open() and post a korean value [ encoded using Javascript encodeURI() ] through the URL, and then if I read the input using PERL from
STDIN, I dont receive the original Korean string. I see some junk content.

CASE-2: On the other side, if I post the Korean value [ encoded with EUC_KR ] using Java to the same CGI window, I could get my original Korean string from the PERL STDIN. In this case, I am before posting
it to the CGI.

For the both the above cases the web server used is Apache (2.0.54)
Is there any way to resolve CASE-1?
Member
 
Join Date: Nov 2006
Posts: 83
#3: Nov 12 '06

re: Cannot get the korean value that was posted to CGI


Without code, that illustrates the problem, it's hard to understand what you mean. But the document, from which you submit the form with Korean characters, should better have the content-type text/html; charset=EUC_KR.
Newbie
 
Join Date: Nov 2006
Posts: 4
#4: Nov 13 '06

re: Cannot get the korean value that was posted to CGI


I am using PERL 5.6 for CGI (Server script).
When a query string containing Korean values is POSTed, the following code gives me the values in ANSI form.
As a result, the I get junk values.
My problem is to read these Korean values properly and not as junk.

Expand|Select|Wrap|Line Numbers
  1. if ($ENV{'REQUEST_METHOD'} eq 'POST') {
  2.     read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
  3. }
  4. else {
  5.     $buf=$ENV{'QUERY_STRING'};
  6. }
  7.  
  8. @fval=split(/&/,$buf);
  9. foreach $i (0 .. $#fval){
  10.     ($name,$val)=split (/=/,$fval[$i],2);
  11.     $val=~tr/+/ /;
  12.     $val=~ s/%(..)/pack("c",hex($1))/ge;
  13.     $name=~tr/+/ /;
  14.     $name=~ s/%(..)/pack("c",hex($1))/ge;
  15.  
  16.     if (!defined($field{$name})) {
  17.         $field{$name}=$val;
  18.     }
  19.     else {
  20.         $field{$name} .= ",$val";
  21.     }
  22. }
Member
 
Join Date: Nov 2006
Posts: 83
#5: Nov 14 '06

re: Cannot get the korean value that was posted to CGI


Quote:

Originally Posted by kumarpl

When a query string containing Korean values is POSTed, the following code gives me the values in ANSI form.
As a result, the I get junk values.

I don't know very much about working with Korean characters, but I have a strong feeling that you are not supposed to use them directly anywhere in a URL. What you can do is including the URI escaped equivalent of the octets that represent the Korean string.

Please consider the following script:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. $ENV{QUERY_STRING} = 'kr_string=%B6%F3%C0%CC%C7%C1%C0%CE%C4%DA%B8%AE%BE%C6';
  4.  
  5. use CGI;                 # Note that these three
  6. my $cgi = CGI->new;      # lines replace all the
  7. my %field = $cgi->Vars;  # code you posted
  8.  
  9. print $cgi->header(-type=>'text/plain', -charset=>'EUC-KR');
  10. print "kr_string: $field{kr_string}\n";
Reply