使用Perl解码URI相关实体

Nik*_*kki 2 perl encoding uri cpan

我甚至可能没有提到这个正确的方式,所以我提前道歉.我们的服务器日志不断向我们展示编码的攻击方式.一个例子如下......

http://somecompany.com/script.pl?var=%20%D1%EB........ (etc etc)
Run Code Online (Sandbox Code Playgroud)

我熟悉使用Perl编码和解码HTML实体(使用HTML :: Entities),但我甚至不确定如何引用这种解码方式.我希望能够编写一个脚本来解码这些URI编码(?).是否有一个模块,任何人都知道这可以指向我正确的方向?

尼克

fri*_*edo 6

使用URI :: Escape模块来转义和转换URI编码的字符串.

例:

use strict;
use warnings;

use URI::Escape;

my $uri = "http://somecompany.com/script.pl?var=%20%D1%EB";
my $decoded = uri_unescape( $uri );
print $decoded, "\n";
Run Code Online (Sandbox Code Playgroud)


Eth*_*her 6

有一些在线资源,如http://www.albionresearch.com/misc/urlencode.php,用于快速编码/解码字符串.

以编程方式,您可以这样做:

use URI::Escape;
my $str  = uri_unescape("%20%D1%EB");
print $str . "\n";
Run Code Online (Sandbox Code Playgroud)

或者干脆:

perl -MURI::Escape -wle'print uri_unescape("%20%D1%EB");'
Run Code Online (Sandbox Code Playgroud)