[PerlChina] Strange Problem: gb2312 showed incorrect in mod_perl, but correct in developer server[catalyst build-in server]

cui robin cuiyuming at gmail.com
Sun Jun 1 22:31:17 PDT 2008


Hi,

When a page loaded in firefox,  then it will send a ajax request to get data
in json format.

Some gb2312 words is in the json data.

When catalyst is started by /home/robin/CBS/script/cbs_server.pl, the data
got by client is same as the data i print on the screen by $c->log->debug().
It's showed corrected in firefox client or ie client.

But when catalyst is running by apache mod_perl, the data got by client is
different from the data i print on the screen by $c->log->debug().It's
showed incorrected.

A chinese world in gb2312 charset have 2 bytes.  what I found in the client
is that:

2 bytes of a chinese word was splited, and a octal byte \303 or \302 was
added before every byte. So showed incorrect in client.

Anyone meet the same problem when using mod_perl?

I use standard JSON module [use JSON;] from cpan,version is 2.07. code like
below:
    my $json = new JSON;
    $json->canonical(1);
    my $response = $json->encode($var);

But i think the problem is nothing to do with JSON,  for some points like
below:
1. The problem will not occur when I use catalyst's built-in server
2. After JSON module convert a hash to JSON data, I use $c->log->debug
output to screen, I saw it was correct.

I think the problem occur when apache (mod_perl) send data to client. the
data was modified. But I don't kown why?
Some code like below:
    my $jsResponse = $ajaxRequest->{response} . "\n$callback_function";
    $c->log->debug("JS Response:\n$jsResponse"); # the showed on the screen
is correct;
    $c->response->content_type('text/html; charset=GB2312');
    $c->response->body($jsResponse);

The mod_perl,apache,perl version like below:
[Mon Jun 02 12:28:31 2008] [notice] Apache/2.0.55 (Unix) PHP/5.2.3
mod_perl/2.0.3 Perl/v5.8.8 configured -- resuming normal operations

Any other solution?

Thanks!

Robincui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/china-pm/attachments/20080602/549ed2f7/attachment.html 


More information about the China-pm mailing list