The server had already added the UTF-8 content type in the HTTP headers
Could you please elaborate which server you are using, and how you configure it to modify the content type of a CGI script? You could also verify in your browser which encoding it uses for your text/plain response.
I also had a look at the source of CGI::Simple and found out:
- The module will decode parameters for you only if you set the global variable $CGI::Simple::PARAM_UTF8 to a true value. That's sort of difficult to guess, since it isn't documented. Of course, you can decode yourself, but it looks like you didn't.
- The module will add ; charset=utf-8 to the content type header only if you print it as print $q->header(-type => 'text/plain');, but not if you just print "Content-type: text/plain\n\n";.
So, the following just works for me:
use strict;
use warnings;
use CGI::Simple;
$CGI::Simple::PARAM_UTF8 = 1;
my $q = CGI::Simple->new();
$q->charset('utf-8');
binmode STDOUT,':encoding(UTF-8)';
print $q->header(-type => 'text/plain');
print $q->param('text'),"\n";
|