HTTP POST、curl 和 mod_python - 如何在没有 HTML FORM 元素的情况下处理 POST 请求?
我正在运行 mod_python 服务器,其中 index.py 旨在处理传入请求。
在index.py中,如果我设计这样的东西来处理表单并获取表单中的详细信息:
<form enctype="multipart/form-data" action="func" method="post">
<p>Input file:<input type="file" name="request"></p>
<p><input type="submit" name="press" value="submit"></p>
并从这样的表单中获取详细信息(注意上面的操作“func”)
def func(req):
message = []
f = req.form.getfirst('request')
它在浏览器中工作得很好。我可以上传一个文件,并且可以在服务器端检索其内容。
但是,我想通过curl的POST发送数据。在这种情况下,我想,
假设我通过curl 的请求是这样的:
curl --data "request=data_i_am_posting" http://mymodpythonsite.com/path/
我的mod_python 请求处理程序应该如何设计,以便我获取我发布的数据。 我应该使用
def index(req):
# What should I do here to get data_i_am_posting
顺便说一句,请注意,浏览器根本不会访问 HTTP 服务器,客户端(curl、脚本)将发布数据并等待非 html 的响应。
I am running a mod_python server, where the index.py is designed to handle the incoming requests.
In the index.py, if I design something like this to handle form and get the details in the form:
<form enctype="multipart/form-data" action="func" method="post">
<p>Input file:<input type="file" name="request"></p>
<p><input type="submit" name="press" value="submit"></p>
And get the details from the form like this (note the action "func" above)
def func(req):
message = []
f = req.form.getfirst('request')
It works perfectly fine from the browser. I can upload a file and its contents can retrieved at the server end.
However, I want to send data via curl's POST. In that case, I thought, the <form> element at the server is not required to handle POST, if I can get the POST data from the request object itself.
Suppose my request via curl is like this:
curl --data "request=data_i_am_posting" http://mymodpythonsite.com/path/
How should my mod_python request handler be designed so that I get the data I am posting.
Should I use the <form> at all?
def index(req):
# What should I do here to get data_i_am_posting
BTW, please note that I HTTP server wont be accessed by browser at all, the clients (curl, scripts) will post data and wait for the response which will be non-html.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先一些注意事项:
因此,对于你的curl命令,你应该能够从“index.py”模块中的这个函数中获得你想要的东西:
-
First a few notes:
So for your curl command, you should be able to get what you want from this function in the "index.py" module:
-