使用perl的CGI :: Cookie-> fetch获取cookie时丢失'+'字符

时间:2013-06-13 14:26:39

标签: perl apache cookies cgi mod-perl

Cookie有价值:

V7S9qwSUTlYYX0gTVO5edmBVyPZkNyMecr6LuABwN3KSgwTyasj1+0pGiN2OJ6s4Jja9ma+BJ0GCCiCFUc8k/uNk/4hIwsZv0KyHVVjOHFHtOq+PHMFaBKg5wRfXReI3LDmiDnIM6h0Z9hrEO5wYha/RadNqIqfJzUTOQl7q33RqQGcx/aLoiizm3tHs05InbAkUqwusJ1E4HFVLFqyvhEunFWrRO1Y/TfrZR7GvCzNiVYGO6O6E1yhup7CAaM6Lc22TjxNfKp1jGJy4NMQUvbMqCOlWZ75sFA4H3jeuNg0RcIC2zCT7l1JU8ZECGPDqf75FoL4qi+9rO0mgdEGgZL3cFk3dSyIApxXYeAR7RlKGsB0vqd4zxdSjTz5LRWK++SPyVNBsKMcVFfHDv7tv4PAUhK4sDT7bfBow9lIwV1f8slchXEcCgLNI2TYZsr/j/GoqnSb9mxp7VGmL7Z4s7cqWdpNsXEpQ3dMM7k4n1lVKOk2qCrzBrqvJRE7mNeaAz6RVjQuroOj0tJOhLUsZeukVbCxORY6k01fNgwPc1v7xGh7y0x6906WOHlcgti4+ofaSxG4AxwWeaf55loL6vN5d5/UEICGlRuxEjpM8X5og2RYhxr/qQWGVBbiZFBkDDd7esG3rXML63cRJ011Du03UzoS2DxKhFeDmrJM7QinuDEAr0UF1p90kj6hN+PqYqfsRONFXjUS8BqjAMJVEoVnnX5uiAAu1MCZc/xDNDzhu10eiib4Tr+7y6yePw7TQm+bunMMFqYVSMMCIapiAsCS70B96UPSgRQHRbzNzeee9ulDvdtXFxdswf89Bi6LwMaPNdcVdq/Cd5KMziRzwqsCli8jkFF7qATgo5E9wU9OueGPlXCnJzdUBu2BG1JaJEZcsDdfczD3vfrVZXy/xQ66OMbwWUn/R02mr3LTiGU5T6pbcsTNbTQyWwc9gNZsjshqBNh5oJ9ScMBI947Gkatf3fkhlH1NJpXX0GNPQ6OqSg+RALq7EEqBRmy4pszu/9BDmmKck6luJzihaAfeFyZC/SwlcUbg/epGmOSAlJRRUBckj1ufuBFMKKd6hkn1qaZUX1fPrCfNVJ7pzVT66tRurqF4HvX8JIKiC/BTPN5ZAw5fkIUJKn+H7x5o1XG9WMFO/AQ/lUVstaB8/hjY+JC6bZapKwsNj

在perl中使用:

%cookies = CGI::Cookie->fetch;
$ticket = $cookies{$ticketKey}->value;
print STDERR $ticket;

我明白了:

V7S9qwSUTlYYX0gTVO5edmBVyPZkNyMecr6LuABwN3KSgwTyasj1 0pGiN2OJ6s4Jja9ma BJ0GCCiCFUc8k/uNk/4hIwsZv0KyHVVjOHFHtOq PHMFaBKg5wRfXReI3LDmiDnIM6h0Z9hrEO5wYha/RadNqIqfJzUTOQl7q33RqQGcx/aLoiizm3tHs05InbAkUqwusJ1E4HFVLFqyvhEunFWrRO1Y/TfrZR7GvCzNiVYGO6O6E1yhup7CAaM6Lc22TjxNfKp1jGJy4NMQUvbMqCOlWZ75sFA4H3jeuNg0RcIC2zCT7l1JU8ZECGPDqf75FoL4qi 9rO0mgdEGgZL3cFk3dSyIApxXYeAR7RlKGsB0vqd4zxdSjTz5LRWK  SPyVNBsKMcVFfHDv7tv4PAUhK4sDT7bfBow9lIwV1f8slchXEcCgLNI2TYZsr/j/GoqnSb9mxp7VGmL7Z4s7cqWdpNsXEpQ3dMM7k4n1lVKOk2qCrzBrqvJRE7mNeaAz6RVjQuroOj0tJOhLUsZeukVbCxORY6k01fNgwPc1v7xGh7y0x6906WOHlcgti4 ofaSxG4AxwWeaf55loL6vN5d5/UEICGlRuxEjpM8X5og2RYhxr/qQWGVBbiZFBkDDd7esG3rXML63cRJ011Du03UzoS2DxKhFeDmrJM7QinuDEAr0UF1p90kj6hN PqYqfsRONFXjUS8BqjAMJVEoVnnX5uiAAu1MCZc/xDNDzhu10eiib4Tr 7y6yePw7TQm bunMMFqYVSMMCIapiAsCS70B96UPSgRQHRbzNzeee9ulDvdtXFxdswf89Bi6LwMaPNdcVdq/Cd5KMziRzwqsCli8jkFF7qATgo5E9wU9OueGPlXCnJzdUBu2BG1JaJEZcsDdfczD3vfrVZXy/xQ66OMbwWUn/R02mr3LTiGU5T6pbcsTNbTQyWwc9gNZsjshqBNh5oJ9ScMBI947Gkatf3fkhlH1NJpXX0GNPQ6OqSg RALq7EEqBRmy4pszu/9BDmmKck6luJzihaAfeFyZC/SwlcUbg/epGmOSAlJRRUBckj1ufuBFMKKd6hkn1qaZUX1fPrCfNVJ7pzVT66tRurqF4HvX8JIKiC/BTPN5ZAw5fkIUJKn H7x5o1XG9WMFO/AQ/lUVstaB8/hjY JC6bZapKwsNj

请注意+字符的丢失?可能是什么导致了这个?我们使用perl v5.8.5和Apache / 2.0.52

2 个答案:

答案 0 :(得分:5)

Cookie值被网址转义,这意味着空格被+字符替换,其他标点符号被%xx代码替换。 CGI::Cookie::fetch方法对值进行解码,并恢复Cookie值中的空格。

如果您不想解码cookie值,可以使用raw_fetch方法。

答案 1 :(得分:0)

代码中的TRY Request.ServerVariables [“HTTP_COOKIE”]值,它提供RAW cookie(不删除cookie数据中的+或=字符)