文件名包含“-”的问题在PERL中
我创建了一个名为“nph-select.pl”的文件,并放置了重定向代码,如下所示。
#!"D:\xampp\perl\bin\perl.exe" -w
use CGI qw/:standard/;
my $cgi = new CGI;
print $cgi->redirect(-uri => 'http://www.google.com/', -nph => 1);
执行文件然后它给我 302 STATUS 消息说“文档已移至此处”。但是,当我通过删除其中的“-”来重命名同一文件时,即新文件名是“nphselect.pl”,那么它也可以通过重定向正常运行。有人能建议我缺少什么设置吗?
我的请求标头是 <代码> 主机本地主机:8080 用户代理 Mozilla/5.0(Windows NT 5.1;rv:2.0.1) Gecko/20100101 Firefox/4.0.1 接受 text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 接受语言 en-us,en;q=0.5 接受编码 gzip、deflate 接受字符集 ISO-8859-1,utf-8;q=0.7,*;q=0.7 保持活力 115 连接保持活动
并且RESPONSE HEADERS 为空。
I have created a file called "nph-select.pl" and put code for redirection as below.
#!"D:\xampp\perl\bin\perl.exe" -w
use CGI qw/:standard/;
my $cgi = new CGI;
print $cgi->redirect(-uri => 'http://www.google.com/', -nph => 1);
and executing file then its gives me 302 STATUS message saying "Document has moved here" . But when I am renaming the same file just by removing "-" in it i.e new file name is "nphselect.pl" then it run properly with redirection also. Can anybody suggect what setting I am missing?
My request headers are
Host localhost:8080
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
And RESPONSE HEADERS are blank.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,一些网络服务器对待以“nph-”开头的 cgi 脚本与任何其他 cgi 脚本不同,因此删除 - 将改变这一点。
您错误地调用了重定向; CGI 的命名参数都必须以 - 开头,如下所示:
使用
uri
而不是-uri
,它使用的是位置参数,因此它会尝试重定向到“url”(其中您的网络服务器可能完全适合您)。如果您要使用 nph- 脚本,设置重定向的 nph 选项会提供更完整的标头集;这可能会解决您的问题:
First, some webservers treat cgi scripts starting 'nph-' differently than any other cgi script, so removing the - will change that.
You are calling redirect incorrectly; CGI's named parameters all must start with -, like this:
With
uri
instead of-uri
, it is using positional parameters, so it tries to redirect to 'url' (which your webserver may fully qualify for you).If you are going to use an nph- script, setting redirect's nph option provides a fuller set of headers; this may resolve your problem: