简体   繁体   English

HTML表单操作最终将下载perl文件,而不是执行它

[英]HTML form action ends up downloading perl file instead of executing it

I have been trying to run a simple perl-cgi script on windows 7. This is a simple HTML form with an OK button where clicking on OK button displays some text. 我一直试图在Windows 7上运行一个简单的perl-cgi脚本。这是一个带有OK按钮的简单HTML表单,其中单击OK按钮会显示一些文本。 But clicking the OK button on the HTML page, instead of executing and displaying perl file's output, the browser starts downloading the script. 但是,单击HTML页面上的“确定”按钮,浏览器开始下载脚本,而不是执行和显示perl文件的输出。 I have added handler in httpd.conf 我在httpd.conf中添加了处理程序

AddHandler cgi-script .pl

But this doesn't help. 但这无济于事。 I added the ExecCGI option in the httpd.conf but that didn't help either. 我在httpd.conf中添加了ExecCGI选项,但这也无济于事。

<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">
    AllowOverride None
    Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

Here is the perl script being used: 这是正在使用的perl脚本:

#!C:\Perl\bin\perl
use CGI;

print "Content-type: text/plain","\n\n";
print "<html>","\n";
print "<head>\n\t<title>Server Information Ready</title>\n</head>","\n";
print "<body>","\n";
print "<h1>Server Information</h1>","\n";
print "</body></html>","\n";

And here is the html file: 这是html文件:

<html>
<head><title>Server Information</title></head>
<body bgcolor="#EEAA55">
<h3>Please click OK to get the server information</h3>
<hr><pre>
<form action="http://localhost/cgi-bin/ctest/pranav1a.pl" method="post">
<input type="submit" value="OK">
</form>
</hr></pre>
</body>
</html>

I have tried this on chrome, IE and Mozilla. 我已经在chrome,IE和Mozilla上进行过尝试。 Mozilla and chrome start the perl file download, but IE just displays some weird content on clicking the OK button. Mozilla和chrome开始下载perl文件,但是IE在单击“确定”按钮时仅显示一些奇怪的内容。 How can I make the browser display output of file execution rather than starting the script download ? 如何使浏览器显示文件执行的输出而不是开始脚本下载?

PS: I have tried to use shebang line as '#!c:/Perl/bin/perl' which doesn't seem to work either. PS:我曾尝试使用shebang行作为'#!c:/ Perl / bin / perl',这似乎也不起作用。 I am able to see the perl script's output when executed from cmd prompt. 从cmd提示符执行时,我能够看到perl脚本的输出。

找到了解决方案:在我的情况下,我在表单操作中使用的是“ localhost”,而不是“ localhost:8080”。

<form action="http://localhost:8080/cgi-bin/pranav1a.pl" method="post">

How about the +ExecCGI option? +ExecCGI选项如何? Try the + in front of it. 尝试前面的+

In addition, these is usually a problem with understanding suexec2 (not sure whether suexec2 applies to a Windows platform): 另外,这些通常是理解suexec2时遇到的问题(不确定suexec2是否适用于Windows平台):

Read the whole page over there . 在那儿阅读整页 Such problems are not fixable when you do not understand the gross limitations enforced by suexec. 当您不了解suexec强制执行的总体限制时,这些问题将无法修复。 Common errors are: 常见错误是:

  • wrong permissions on suexec2 executable. suexec2可执行文件的权限错误。
  • CGI script is located in wrong location. CGI脚本位于错误的位置。

Have you worked through apache.org/docs/2.2/howto/cgi.html#troubleshoot yet? 您是否已完成apache.org/docs/2.2/howto/cgi.html#troubleshoot的工作?

Thanks Scavokovich. 感谢Scavokovich。

In my case the following line was commented out in the httpd.conf file. 在我的情况下,在httpd.conf文件中注释了以下行。

#LoadModule cgi_module /opt/freeware/lib64/httpd/modules/mod_cgi.so

Uncommenting it, and restarting apache allowed the CGI script to run instead of open as a text file. 取消注释,然后重新启动apache允许CGI脚本运行,而不是作为文本文件打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM