localhost:6334 和 localhost:{insert username here} 有什么区别?
what is the difference between localhost:6334 and localhost:{insert username here}?
至少我认为这是表达我的问题的最佳方式。我是一名新的编程学生,老师在他的笔记中有这个例子,他从来没有接触过。我正在做的是使用 cgi 脚本提交一个简单的表单。我将 WebStorm 用作 IDE,当我尝试在我的网页上提交表单时,我 运行 遇到了麻烦。以下是我正在使用的三个代码文件:
html 页数:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Testing Form submission</title>
</head>
<body>
<h2>Testing Simple Form</h2>
<form name="test_form" method="post" action="form_submission.sh">
First Name: <input type="text" name="firstName"/><br/>
Last Name: <input type="text" name="lastName"/><br/>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
cgi 脚本:
#!/usr/bin/env bash
source cgi_vars.sh
# register all GET and POST variables
cgi_getvars BOTH ALL
echo "Content-type: text/html"
echo
echo "<html>"
echo "<head>"
echo "<title>Form Submitted</title>"
echo "</head>"
echo "<body>"
echo "<h2>The values you submitted were:</h2>"
echo "First Name: ${firstName}<br/>"
echo "Last Name: ${lastName}<br/>"
echo "</body>"
echo "</html>"
和脚本引用的其他一些文件,但我不确切知道它的用途或作用...:[=14=]
#!/usr/bin/env bash
# (internal) routine to store POST data
function cgi_get_POST_vars()
{
# check content type
# FIXME: not sure if we could handle uploads with this..
[ "${CONTENT_TYPE}" != "application/x-www-form-urlencoded" ] && \
echo "bash.cgi warning: you should probably use MIME type "\
"application/x-www-form-urlencoded!" 1>&2
# save POST variables (only first time this is called)
[ -z "$QUERY_STRING_POST" \
-a "$REQUEST_METHOD" = "POST" -a ! -z "$CONTENT_LENGTH" ] && \
read -n $CONTENT_LENGTH QUERY_STRING_POST
# prevent shell execution
local t
t=${QUERY_STRING_POST//%60//} # %60 = `
t=${t//\`//}
t=${t//$(//}
t=${t//%24%28//} # %24 = $, %28 = (
QUERY_STRING_POST=${t}
return
}
# (internal) routine to decode urlencoded strings
function cgi_decodevar()
{
[ $# -ne 1 ] && return
local v t h
# replace all + with whitespace and append %%
t="${1//+/ }%%"
while [ ${#t} -gt 0 -a "${t}" != "%" ]; do
v="${v}${t%%\%*}" # digest up to the first %
t="${t#*%}" # remove digested part
# decode if there is anything to decode and if not at end of string
if [ ${#t} -gt 0 -a "${t}" != "%" ]; then
h=${t:0:2} # save first two chars
t="${t:2}" # remove these
v="${v}"`echo -e \\x${h}` # convert hex to special char
fi
done
# return decoded string
echo "${v}"
return
}
# routine to get variables from http requests
# usage: cgi_getvars method varname1 [.. varnameN]
# method is either GET or POST or BOTH
# the magic varible name ALL gets everything
function cgi_getvars()
{
[ $# -lt 2 ] && return
local q p k v s
# prevent shell execution
t=${QUERY_STRING//%60//} # %60 = `
t=${t//\`//}
t=${t//$(//}
t=${t//%24%28//} # %24 = $, %28 = (
QUERY_STRING=${t}
# get query
case in
GET)
[ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
;;
POST)
cgi_get_POST_vars
[ ! -z "${QUERY_STRING_POST}" ] && q="${QUERY_STRING_POST}&"
;;
BOTH)
[ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
cgi_get_POST_vars
[ ! -z "${QUERY_STRING_POST}" ] && q="${q}${QUERY_STRING_POST}&"
;;
esac
shift
s=" $* "
# parse the query data
while [ ! -z "$q" ]; do
p="${q%%&*}" # get first part of query string
k="${p%%=*}" # get the key (variable name) from it
v="${p#*=}" # get the value from it
q="${q#$p&*}" # strip first part from query string
# decode and evaluate var if requested
[ "" = "ALL" -o "${s/ $k /}" != "$s" ] && \
eval "$k=\"`cgi_decodevar \"$v\"`\""
done
return
}
因此,当我在 WebStorm 中并单击其中一个浏览器选项时,它将使用 localhost:6334/filepath 打开文件。这样做之后,当我尝试提交表单时,它会出于某种原因开始下载 cgi 脚本。但是,如果我只导航到本地主机,我会注意到它已准备好我的所有文件,所以当我从那里单击打开 html 文件并提交表单时,它与 cgi 一起工作正常。
那么我的代码中有什么问题吗?还是两种获取 html 文件的方式之间存在根本区别?或者我需要更改某些服务器文件中的某些设置?
好吧,WebStorm 内置网络服务器(提供来自 localhost:63342/filepath
的文件)是一个简单的静态网络服务器,POST 像您这样的请求是使用静态文件处理程序处理的 - 即服务器只是 returns 指定 URL 处可用的文件内容 - 仅此而已。您必须在 'just localhost' 有一个不同的网络服务器服务文件,可以不同地处理 POST 请求...
至少我认为这是表达我的问题的最佳方式。我是一名新的编程学生,老师在他的笔记中有这个例子,他从来没有接触过。我正在做的是使用 cgi 脚本提交一个简单的表单。我将 WebStorm 用作 IDE,当我尝试在我的网页上提交表单时,我 运行 遇到了麻烦。以下是我正在使用的三个代码文件:
html 页数:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Testing Form submission</title>
</head>
<body>
<h2>Testing Simple Form</h2>
<form name="test_form" method="post" action="form_submission.sh">
First Name: <input type="text" name="firstName"/><br/>
Last Name: <input type="text" name="lastName"/><br/>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
cgi 脚本:
#!/usr/bin/env bash
source cgi_vars.sh
# register all GET and POST variables
cgi_getvars BOTH ALL
echo "Content-type: text/html"
echo
echo "<html>"
echo "<head>"
echo "<title>Form Submitted</title>"
echo "</head>"
echo "<body>"
echo "<h2>The values you submitted were:</h2>"
echo "First Name: ${firstName}<br/>"
echo "Last Name: ${lastName}<br/>"
echo "</body>"
echo "</html>"
和脚本引用的其他一些文件,但我不确切知道它的用途或作用...:[=14=]
#!/usr/bin/env bash
# (internal) routine to store POST data
function cgi_get_POST_vars()
{
# check content type
# FIXME: not sure if we could handle uploads with this..
[ "${CONTENT_TYPE}" != "application/x-www-form-urlencoded" ] && \
echo "bash.cgi warning: you should probably use MIME type "\
"application/x-www-form-urlencoded!" 1>&2
# save POST variables (only first time this is called)
[ -z "$QUERY_STRING_POST" \
-a "$REQUEST_METHOD" = "POST" -a ! -z "$CONTENT_LENGTH" ] && \
read -n $CONTENT_LENGTH QUERY_STRING_POST
# prevent shell execution
local t
t=${QUERY_STRING_POST//%60//} # %60 = `
t=${t//\`//}
t=${t//$(//}
t=${t//%24%28//} # %24 = $, %28 = (
QUERY_STRING_POST=${t}
return
}
# (internal) routine to decode urlencoded strings
function cgi_decodevar()
{
[ $# -ne 1 ] && return
local v t h
# replace all + with whitespace and append %%
t="${1//+/ }%%"
while [ ${#t} -gt 0 -a "${t}" != "%" ]; do
v="${v}${t%%\%*}" # digest up to the first %
t="${t#*%}" # remove digested part
# decode if there is anything to decode and if not at end of string
if [ ${#t} -gt 0 -a "${t}" != "%" ]; then
h=${t:0:2} # save first two chars
t="${t:2}" # remove these
v="${v}"`echo -e \\x${h}` # convert hex to special char
fi
done
# return decoded string
echo "${v}"
return
}
# routine to get variables from http requests
# usage: cgi_getvars method varname1 [.. varnameN]
# method is either GET or POST or BOTH
# the magic varible name ALL gets everything
function cgi_getvars()
{
[ $# -lt 2 ] && return
local q p k v s
# prevent shell execution
t=${QUERY_STRING//%60//} # %60 = `
t=${t//\`//}
t=${t//$(//}
t=${t//%24%28//} # %24 = $, %28 = (
QUERY_STRING=${t}
# get query
case in
GET)
[ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
;;
POST)
cgi_get_POST_vars
[ ! -z "${QUERY_STRING_POST}" ] && q="${QUERY_STRING_POST}&"
;;
BOTH)
[ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
cgi_get_POST_vars
[ ! -z "${QUERY_STRING_POST}" ] && q="${q}${QUERY_STRING_POST}&"
;;
esac
shift
s=" $* "
# parse the query data
while [ ! -z "$q" ]; do
p="${q%%&*}" # get first part of query string
k="${p%%=*}" # get the key (variable name) from it
v="${p#*=}" # get the value from it
q="${q#$p&*}" # strip first part from query string
# decode and evaluate var if requested
[ "" = "ALL" -o "${s/ $k /}" != "$s" ] && \
eval "$k=\"`cgi_decodevar \"$v\"`\""
done
return
}
因此,当我在 WebStorm 中并单击其中一个浏览器选项时,它将使用 localhost:6334/filepath 打开文件。这样做之后,当我尝试提交表单时,它会出于某种原因开始下载 cgi 脚本。但是,如果我只导航到本地主机,我会注意到它已准备好我的所有文件,所以当我从那里单击打开 html 文件并提交表单时,它与 cgi 一起工作正常。
那么我的代码中有什么问题吗?还是两种获取 html 文件的方式之间存在根本区别?或者我需要更改某些服务器文件中的某些设置?
好吧,WebStorm 内置网络服务器(提供来自 localhost:63342/filepath
的文件)是一个简单的静态网络服务器,POST 像您这样的请求是使用静态文件处理程序处理的 - 即服务器只是 returns 指定 URL 处可用的文件内容 - 仅此而已。您必须在 'just localhost' 有一个不同的网络服务器服务文件,可以不同地处理 POST 请求...