我为www编写了CGI脚本.
此脚本需要通过GET方法的两个参数,将这些数字相乘并将结果写入文件.
mult.cgi?m=1&n=2
Run Code Online (Sandbox Code Playgroud)
但现在我也希望从控制台使用这个脚本.我想做点什么
./mult.cgi?m=1&n=2
Run Code Online (Sandbox Code Playgroud)
但它没有用,怎样才能将参数发送到脚本?
谢谢.
我正在构建一个简单的python CGI脚本来与Twilio一起使用.现在,它只输出一些简单的XML,但我希望它能够处理和响应POST请求(以获得传入的调用者ID).最后,我将使用完整的Web应用程序框架,如Django; 但是,就目前而言,我只想要一个可以与Twilio互动的简单服务.最简单的方法是什么?
提前致谢.
我正在使用CGI.pm模块编写Perl/CGI脚本.我可以返回text/html,但不能在其中包含图像,它总是显示'alt'标签,我确定href链接.
这是我的代码:
#!/usr/bin/perl -w
use strict;
use CGI;
my $cgi = new CGI;
print $cgi->header(-type=>'text/html'),
$cgi->start_html(-title=>'Test Page'),
$cgi->h1('Infos switch'),
"This is a test.",
$cgi->h1('Testing'), $cgi->hr, "\n",
$cgi->img(-src=>'http://www.perl.org/simages/lcamel.gif',
-alt=>'Powered by Perl'), "\n\n",
$cgi->end_html;
exit;
Run Code Online (Sandbox Code Playgroud) 我正在创建一个带有Perl后端的Facebook应用程序.问题是,由于Facebook将请求作为POST请求发送到我的Web应用程序,我在获取GET参数时遇到问题,这些参数也是应用程序的基本URL的一部分 - 实际上我只获得POST参数来自$ CGI-> Vars.
我试图将参数传递给python cgi脚本,此参数包含加号运算符.
/cgi-bin/test.py?input=print%20"%20"%20"%20%20-+-\"
Run Code Online (Sandbox Code Playgroud)
python cgi脚本很简单:
#!/usr/bin/python -w
import cgi
fs = cgi.FieldStorage()
print "Content-type: text/plain\n"
strE=fs.getvalue("input")
print strE
Run Code Online (Sandbox Code Playgroud)
我的输出是:
print " " " - -\"
Run Code Online (Sandbox Code Playgroud)
我不明白为什么'+'加运算符被空格替换,我怎么可以通过'+'加运算符?
编辑
@Tom Anderson回答了我的问题,我想再提一下我的问题.
我有一个java脚本函数调用获取带参数的url:
<script type="text/javascript">
function PostContentEditable(editableId,targetOutput)
{
var texthtml = document.getElementById(editableId).innerHTML
var tmp = document.createElement("DIV");
tmp.innerHTML = texthtml ;
var str= tmp.textContent||tmp.innerText;
var xmlhttp;
if (str.length == 0){
document.getElementById(targetOutput).innerHTML = "";
return;
}
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById(targetOutput).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","../cgi-bin/exercise.py?input="+str,true);
xmlhttp.send();
} …Run Code Online (Sandbox Code Playgroud) 我在使用perl工作时获得简单的DBI连接时遇到问题.
我放置一个地方检查器来查看数据库句柄是否未定义,并且它总是未定义.有任何明显的错误吗?我确信我输入的信息是正确的,因为我在PHP脚本中使用它.
#!/usr/bin/perl -w
use warnings;
print "Content-Type: text/html\n\n";
use DBI;
# Connecting to the database
# Replace DATABASENAME with the name of the database,
# HOSTNAME with the hostname/ip address of the MySQL server.
$drh = DBI->install_driver("mysql");
$dsn = "DBI:mysql:database=db_name;host=host_name";
$dbh = DBI->connect($dsn,"username","password");
if(defined $dbh)
{
print "Yes<br />";
}
else
{
print "No<br />";
}
# Select the data and display to the browser
$sth = $dbh->prepare("SELECT * FROM customer");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
print …Run Code Online (Sandbox Code Playgroud) <script type="text/javascript">
var id = getValue("ID");
document.write(id);
</script>
<form action="cgi-bin/runalg.cgi" method="post" enctype="multipart/form-data">
<input type="radio" name="genome" value="E.Coli"> <i>E.Coli</i> <input type="radio" name="genome" value="Human"> Human<br>
<input type="submit" name="submit" value="Submit"/>
<input type="reset" name="reset" value="Clear"/>
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
如何将JavaScript变量(var id)的值放入表单中,以便在提交时我可以runalg.cgi使用$q<-param("ID")命令检索它?
我有一个关于学生数据的应用程序,我正在尝试创建一个广播组,其中包含有关学生性别的选项.但它显示以下错误:未定义的子程序CGI :: radio at C:/wamp/bin/apache/apache2.2.22/cgi-bin/modify.pl 196
$cInput .= $q->div({-class => 'control-group'},
$q->label({-class => 'control-label', -for => 'gender'}, "Gender:"),
$q->div({class => 'controls'},
$q->span({class => 'span12'},
$q->label({-class => 'blue'},
$q->radio-group({-id => 'gender', -name => 'gender', -values => ['M','F'],-labels => \%labels, -default => $cGender, 'true'})))));
Run Code Online (Sandbox Code Playgroud)
可能是什么问题?
我想有条件地设置一个哈希键/值.我做了一些搜索,但似乎无法找到我的查询的正确条款.谢谢!
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $q = new CGI;
my $foo = $q->cookie('Foo');
my $uri = 'https://www.google.com';
#is there a way to do this more elegantly?
print $q->redirect(-uri => $uri, -cookie => $foo) if ($foo);
print $q->redirect($uri) unless ($foo);
Run Code Online (Sandbox Code Playgroud) 我想在perl CGI文件中运行javascript.代码如下
#!C:\wamp\bin\perl\bin\perl.exe
$html = "Content-Type: text/html
<HTML>
<HEAD>
<TITLE>Hello World</TITLE>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
alert("i am here");
</SCRIPT>
</HEAD>
<BODY>
<H4>Hello World</H4>
<P>
Your IP Address is $ENV{REMOTE_ADDR}
<P>
<H5>Have a nice day</H5>
</BODY>
</HTML>";
print $html;
Run Code Online (Sandbox Code Playgroud)
我收到内部服务器错误.
只有html的代码工作正常请让我知道在Perl中包含javascript需要做些什么