我看到 PHP 中有一个virtual()函数可以调用 CGI 脚本,但这是最好的方法吗?我也可以将任何参数传递给该脚本吗?
我看到一些使用file_get_contents()或include()并传入 CGI 脚本的 URL 的示例,但这感觉像是黑客攻击。
当我尝试在支持 perl 的 Web 服务器中运行以下代码时,出现 500 内部服务器错误:
#! /usr/bin/perl
use LWP;
my $ua = LWP::UserAgent->new;
$ua->agent("TestApp/0.1 ");
$ua->env_proxy();
my $req = HTTP::Request->new(POST => 'http://www.google.com/loc/json');
$req->content_type('application/jsonrequest');
$req->content('{ "cell_towers": [{"location_area_code": "55000", "mobile_network_code": "95", "cell_id": "20491", "mobile_country_code": "404"}], "version": "1.1.0", "request_address": "true"}');
my $res = $ua->request($req);
if ($res->is_success) {
print $res->content,"\n";
} else {
print $res->status_line, "\n";
return undef;
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行下面的代码时没有错误:
#! /usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD><TITLE>Hello World!</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H2>Hello World!</H2> <br /> \n";
foreach …Run Code Online (Sandbox Code Playgroud) 我制作了如下简单的网络服务器。
import BaseHTTPServer, os, cgi
import cgitb; cgitb.enable()
html = """
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data">
File upload: <input type="file" name="upfile">
<input type="submit" value="upload">
</form>
</body>
</html>
"""
class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("content-type", "text/html;charset=utf-8")
self.end_headers()
self.wfile.write(html)
def do_POST(self):
ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
if ctype == 'multipart/form-data':
query = cgi.parse_multipart(self.rfile, pdict)
upfilecontent = query.get('upfile')
if upfilecontent:
# i don't know how to get the file name.. so i named it 'tmp.dat'
fout = file(os.path.join('tmp', 'tmp.dat'), 'wb')
fout.write (upfilecontent[0])
fout.close() …Run Code Online (Sandbox Code Playgroud) 在 MS-Windows 上的 JDK 的 bin 目录(至少到 Java 8)中,有以下文件java-rmi.exe:
30.01.2014 15:28 15.752 java-rmi.exe
Run Code Online (Sandbox Code Playgroud)
在 Unix 上,有一个名为 的类似文件java-rmi.cgi,因此我想这些可执行文件已用于支持 RMI 的某些(传统的、古老的)CGI 接口(实际上,java-rmi.cgi是一个启动 的简单 shell 脚本java)。
我发现这个网站解释了 Unix 上的用法java-rmi.cgi,但没有参考java-rmi.exe:http://docs.oracle.com/javase/jp/8/platform/rmi/spec/rmi-arch6.html
那么,java-rmi.exeMS-Windows就是java-rmi.cgiUnix 的对应版本吗?
这应该是我关于 FastCGI 和 NGINX 的最后一个问题(我已经问了太多了),但是我有一个关于在 Web 服务器上运行 C FastCGI 脚本的问题,特别是 NGINX。现在我的 nginx.conf 文件是这样的:
user nobody nobody;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
location / {
root /nginx/html;
index index.html index.htm new.html;
autoindex on;
fastcgi_pass 127.0.0.1:8000;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个简单的 C FastCGI 脚本,可以打印出 Hello World。我知道为了运行这个脚本,我首先必须编译 C 脚本,这将生成一个二进制文件。然后我使用spawn-fcgi -p 8000 -n <binary>or执行这个二进制文件cgi-fcgi -start -connect localhost:8000 ./<binary>。我已经成功地做到了这一点并显示了正确的结果。然而,当我这样做时,CGI 脚本是 Web 服务器上唯一显示的内容。我无法访问任何 .html 页面或任何其他页面。即使我输入随机扩展名(这会导致 404 Page not Found 错误),也会显示 CGI 脚本。基本上我试图让index.html成为主页,然后当用户单击按钮时,用户将被带到一个显示C CGI脚本的新页面。
这可能吗?如果是这样,我该怎么办?我花了几个小时试图在网上寻找解决方案,但没有成功。如果问题太模糊/不清楚或者您需要更多信息,请告诉我!谢谢你!
我到处寻找并尝试了许多建议的解决方案,但仍然没有所需的结果:从我的 lamp 服务器运行 python 文件。我似乎无法整合拼图的所有部分......使故事变得复杂的是,许多解决方案要么使用旧的 apache 版本(<2.4),这显着改变了配置文件。不再有 httpd.conf!所以这个在apache2中执行a-python-script-in-apache2没有帮助;但 python 版本 > 3 也让事情变得复杂。
眼镜:
python 脚本是最简单的脚本,已可执行
#!/usr/bin/env python3
print ("Content-type: text/html\n")
print ("Hello world!")
Run Code Online (Sandbox Code Playgroud)让我们把它归结为最简单的情况:我想让apache解释spark.py脚本并吐出html:“Hello world!”
问题:
我知道出于安全原因,您不应该在根目录中放置 apache 运行脚本。
我正在为库存系统编写 Python CGI 脚本。它需要通过对象pickle列表(称为locations)进行存储。这是我正在使用的代码:
try:
with open(".config/autosave.bin", "rb") as dataFile:
locations = pickle.load(dataFile)
except (FileNotFoundError, PermissionError):
dispHTML("p", contents="Error in load: Save file incorrectly configured!")
locations = []
Run Code Online (Sandbox Code Playgroud)
但是,这会导致:
/Applications/MAMP/cgi-bin/ic/main.py in ()
16 try:
17 with open(".config/autosave.bin", "rb") as dataFile:
=> 18 locations = pickle.load(dataFile)
19 except (FileNotFoundError, PermissionError):
20 dispHTML("p", contents="Error in load: Save file incorrectly configured!")
AttributeError: Can't get attribute 'Location' on <module '__main__' from '/Applications/MAMP/cgi-bin/ic/main.py'>
args = ("Can't get attribute 'Location' on <module '__main__' …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行 pyhton cgi。在 apache wamp 服务器上。代码的 HTML 端工作正常,但是当它转向 python 脚本时。我收到以下错误:
来自脚本“test.py”的格式错误的标头:错误标头:
FISCAL_WEEK_NUMBER .,引用:http://localhost/test.html
我尝试在 IDE 上单独测试我的 python 代码,它工作正常。我无法在这里找到问题。下面是我的代码:
#!C:/Program Files (x86)/Python36-32/python.exe
import cgi
import os
import cgitb;
import pandas as pd
import teradata
import numpy as np
os.environ["USERNAME"] = "hjoshi"
form = cgi.FieldStorage()
# Get filename here.
fileitem = form['filename']
# Test if the file was uploaded
if fileitem.file:
fn = os.path.basename(fileitem.filename)
query = "insert into p_piw_stg.sales_goals_test_harsh (?, ?, ?, ?)" #insert query for database
input = pd.read_excel('C:/Users/hjoshi/Downloads/' + …Run Code Online (Sandbox Code Playgroud) 已安装具有 IIS 角色的 ISAPI 和 CGI,但它们被禁用,如附图所示。角色和 IIS 窗口的屏幕 截图 这里让我有点头疼。
我是 Perl 的初学者。
我的理解如下。
看起来很好。然而,在我使用 Golang、Nginx 等进行现代开发的经验中,我从未见过 FCGI。
现代 Web 应用程序不再需要 FCGI 了吗?
FCGI的缺点是什么,FCGI的优点是什么?