【问题标题】:How to pass a HTTP parameter from a CP1251 page to a UTF-8 handler?如何将 HTTP 参数从 CP1251 页面传递到 UTF-8 处理程序?
【发布时间】:2017-02-14 02:40:15
【问题描述】:

当我在下面的 Perl 程序的输入中键入一个俄语单词并单击提交时,我看到一个废话而不是俄语字母。

如何将编码为 CP1251 的页面中的数据传递给需要 UTF-8 字符串的处理程序脚本? (下面的脚本是这种情况的一个简单示例。)

#!/usr/bin/perl

use strict;
use warnings;

use CGI qw/param/;

if (param('x')) {
  print "Content-Type: text/plain; charset=utf-8\n\n";
  print "[[".param('x')."]]";
} else {
  print "Content-Type: text/html; charset=windows-1251\n\n";
  print '<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"></head>';
  print "<form><input name='x'/><input type='submit'/></form>";
}

【问题讨论】:

    标签: perl encoding character-encoding cgi param


    【解决方案1】:

    我可以将param() 的值从CP1251 转换为UTF-8 或将accept-charset='utf-8' 属性添加到&lt;form&gt; 元素。

    【讨论】:

    猜你喜欢
    • 2014-09-02
    • 1970-01-01
    • 1970-01-01
    • 2014-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多