我有一个客户端应用程序,它通过 AJAX POST 请求 ( request.open("POST", url, flag)) 向我的 Perl CGI 脚本提交一些数据。
如何使用 Perl 检索此数据并返回一些其他数据(AJAX 响应)?
我继承了一个使用 CGI 脚本的代码库。据我所知,它们效率很低,因为每次收到请求时它们都会分叉一个新进程。我目前正在尝试将它们转换为 WSGI,但我对以下内容感到困惑:
WSGI 和 CGI 在代码方面有何不同?我知道该应用程序必须是可调用的,但除此之外,我不确定还需要做什么来更改它。
我如何衡量我所看到的效率提升随着变化而明显的变化?
其他可能有用的信息是我将使用 Apache 和 mod_wsgi。
如果我可以提供任何其他信息,请告诉我。
使用 py2.7 和 py3.7 都会出现此错误
在此处输入代码
Exception happened during processing of request from ('10.0.2.15', 41994)
Traceback (most recent call last):
File "/usr/lib/python3.8/socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib/python3.8/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.8/socketserver.py", line 720, in __init__
self.handle()
File "/usr/lib/python3.8/http/server.py", line 427, in handle
self.handle_one_request()
File "/usr/lib/python3.8/http/server.py", line 415, in handle_one_request
method()
File "/usr/share/set/src/webattack/harvester/harvester.py", line 334, in do_POST
filewrite.write(cgi.escape("PARAM: " + line + "\n"))
AttributeError: module 'cgi' has no attribute 'escape'
Run Code Online (Sandbox Code Playgroud) 我尝试使用Perl CGI设置cookie没有成功.
我的代码看起来像这样:
$qry = new CGI
$cookie = $qry->cookie(-name=>'SERVER_COOKIE',
-value=>'USER_NAME',
-path=>'/'),
$qry->header(-cookie=>$cookie)
Run Code Online (Sandbox Code Playgroud)
页面不会抛出任何错误,但没有设置cookie!
我使用Firefox 3.5.5与附加组件来查看cookie.
我究竟做错了什么?
迦特
嗨,我刚刚IF在我的源中添加了一个条件,从那时起我就收到了错误
"
_HTML_在EOF之前的任何地方找不到字符串终结符"
但如果我删除它,它的工作原理 IF
我是Perl和CGI的新手,我不知道如何解决这个错误.
这是我的代码:
#!"\xampp\perl\bin\perl.exe"
use CGI qw/:standard/;
use CGI::Cookie;
%cookies = CGI::Cookie->fetch;
$Cookie = $cookies{'USER'}->value;
if ($Cookie)
{
print "Content-type: text/html\n\n";
print<<_HTML_;
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7 lt8"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8 lt8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head> …Run Code Online (Sandbox Code Playgroud) 我正在使用Xampp来测试我的perl cgi脚本.当我打开cgi脚本时,css似乎不适用于该页面.我在html文件中尝试了完全相同的代码,它工作正常,这表明html链接到正确的位置,以找到CSS.
$self->{content}=<<HTML;
<!DOCTYPE html>
<html>
<head>
<title>$title</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="../css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="../css/additional.css" rel="stylesheet" media="screen">
<script src="http://code.jquery.com/jquery.js"></script>
<script src="../js/bootstrap.min.js"></script>
</head>
<body>
<div class="navbar">
<div class="navbar-inner">
<a class="brand" >Bridge : $env </a>
<ul class="nav">
<li><a href="#"><i class="icon-upload"></i>upload</a></li>
<li><a href="#"><i class="icon-search"></i>Search</a></li>
<li><a href="#"><i class="icon-cog"></i>Admin</a></li>
</ul>
</div>
</div>
<div class="container">
...
</div>
</body>
</html>
HTML
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试从文本框中将数据插入数据库,$ enter/$ enter2是文本写入的位置.
该数据库由三列ID,name和nametwo组成
ID是自动递增并且工作正常
这两个语句都可以自行运行,但由于它们是单独发布的,因此第一个叶子名称为空白而第二个叶子名称为空白.
我试过结合两者但没有太多运气,希望有人可以提供帮助.
$dbh->do("INSERT INTO $table(name) VALUES ('".$enter."')");
$dbh->do("INSERT INTO $table(nametwo) VALUES ('".$enter2."')");
Run Code Online (Sandbox Code Playgroud) 下面的代码是我们正在使用的Perl CGI脚本的原始代码.即使对于非常大的文件,它似乎也在起作用,但对于非常大的文件却不行.
目前的代码是:
$files_location = $c->{target_dir}.'/'.$ID;
open(DLFILE, "<$files_location") || Error('open', 'file');
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$name\n\n";
print @fileholder;
binmode $DLFILE;
Run Code Online (Sandbox Code Playgroud)
如果我正确理解代码,它会在"打印"它之前将整个文件加载到内存中.当然我觉得加载和显示它会更好吗?但在阅读了许多论坛和教程之后,我仍然不确定如何做到最好,使用标准的Perl库...
最后一个问题,为什么最后指定"binmode"?
非常感谢任何提示或建议,
我正在尝试使用perl脚本在浏览器中打印XML文件.当我尝试在浏览器中运行脚本时,我遇到以下错误.
Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
Premature end of script headers: get_data.pl
If you think this is a server error, please contact the webmaster.
Error 500
localhost
01/15/10 14:29:28
Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1
Run Code Online (Sandbox Code Playgroud)
这是我的脚本.我也使用语法检查器检查了语法.我的perl配置没问题,因为其他简单的perl脚本工作正常.我认为问题在于"使用CGI"; 引导我..
#!/usr/local/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $r = new CGI();
my $id = $r->param('id');
if(!defined($id))
{
print "Content-type: text/html\n\nMissing parameter: id\n";
exit 1;
}
if($id eq …Run Code Online (Sandbox Code Playgroud) 我遇到的问题是标签在chrome中被误解,但在Firefox中没有.我有一个cgi脚本,它生成一个图像和一个图像的链接.
CGI脚本
if (-e $FILENAME)
{
print qq#<a href="http://blah.com/downloadfile.cgi?ID=$FILENAME"><b>Image:</b></a> #;
print qq#<img src="http://blah.com/viewimage.cgi?ID=$FILENAME"> </img>#;
}
Run Code Online (Sandbox Code Playgroud)
Firefox解读
<a href="http://blah.com/downloadfile.cgi?ID=/temp_webfiles/af08e6f3291a912cf8031984acc7942a.jpg"><b>Image:</b></a> <img src="http://blah.com/viewimage.cgi?ID=/temp_webfiles/af08e6f3291a912cf8031984acc7942a.jpg">
Chrome解读
<a href="http://blah.com/downloadfile.cgi?ID=/temp_webfiles/5eb1834ce2ea527df6c341a915b5a6fb.jpg"><b>Image:</b><img src="http://blah.com/viewimage.cgi?ID=/temp_webfiles/5eb1834ce2ea527df6c341a915b5a6fb.jpg"></a>
只需注意,Chrome和Firefox的图像名称会有所不同,只是随机创建.
如您所见,对于结束图像标记都没有显示,对于chrome,标记被误解.
这有什么原因吗?有什么建议?
谢谢,