[英]HTTP POST, curl and mod_python - How to handle POST request without HTML FORM element?
I am running a mod_python server, where the index.py is designed to handle the incoming requests. 我正在运行一个mod_python服务器,其中index.py用于处理传入的请求。
In the index.py, if I design something like this to handle form and get the details in the form: 在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>
And get the details from the form like this (note the action "func" above) 并从这样的表单中获取详细信息(请注意上面的操作“func”)
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. 但是,我想通过curl的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. 在那种情况下,我想,如果我可以从请求对象本身获取POST数据,则服务器上的<form>元素不需要处理POST。
Suppose my request via curl is like this: 假设我通过curl的请求是这样的:
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. 我应该如何设计我的mod_python请求处理程序,以便获取我发布的数据。 Should I use the <form> at all? 我应该使用<form>吗?
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. 顺便说一句,请注意我的HTTP服务器根本不会被浏览器访问,客户端(curl,脚本)将发布数据并等待非html的响应。
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: 因此,对于curl命令,您应该能够在“index.py”模块中从此函数中获得所需内容:
def path(req):
request_data = req.form.getfirst('request')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.