简体   繁体   English

[Shell脚本]在Shell脚本中获取httpreqest POST

[英][Shell Script]Get httpreqest POST in shell script

Is it possible to get POST data from client side( by ajax) and process it in shell script? 是否有可能从客户端(通过ajax)获取POST数据并在shell脚本中对其进行处理?

I use jQuery to send data to my server side as 我使用jQuery将数据发送到我的服务器端

$.ajax({
    url: "test.cgi",
    type: "post",
    data:{
        test: "123"
    },
    dataType: "json"
});

and I hope I can process the data( as '123' in the sample) in my shell script. 我希望可以在我的shell脚本中处理数据(示例中为“ 123”)。

If I use GET , I can use $QUERY_STRING to get data in my server side, 如果使用GET ,则可以使用$QUERY_STRING在服务器端获取数据,

but I afraid the datas I send to server are too much, so I use POST instead. 但是我担心发送到服务器的数据太多,所以我改用POST

My server is Linux and my shell script is Bourne Shell( starts with #!/bin/sh ). 我的服务器是Linux,我的shell脚本是Bourne Shell(以#!/bin/sh开头)。

Or is there others method to handle this situation? 还是有其他方法可以处理这种情况?

Thanks in advanced!. 提前致谢!。

Edit: 编辑:

I have web page called test.html, and there is input box, user write '123' in the input box, then click button( not type='submit', just type='button', because I want to use ajax, not use form and let web page load to server side web page), the button will run the ajax in POST to server side cgi--- test.cgi 我有一个名为test.html的网页,并且有一个输入框,用户在输入框中输入“ 123”,然后单击button(不是type ='submit',只是type ='button',因为我想使用ajax,不使用表单,让网页加载到服务器端网页),该按钮将在POST中运行Ajax到服务器端cgi --- test.cgi

In test.cgi, I want to get the data that client side POST to it and process it( as save the data '123' to a file. 在test.cgi中,我想获取客户端POST到它的数据并进行处理(将数据'123'保存到文件中。

What you use to send the POST is completely irrelevant. 您用于发送POST内容完全不相关。 If your shell script is invoked as a regular CGI script, the POST data will be available on standard input. 如果将您的Shell脚本作为常规CGI脚本调用,则POST数据将在标准输入中可用。

#!/bin/sh
cat >file

Perhaps you want to add unwrapping of the application/x-www-form-urlencoded container but in essence, the above is all it takes to do what you are asking. 也许您想添加对application/x-www-form-urlencoded容器的解包,但从本质上讲,以上就是完成您所要完成的全部工作。

Here's the obligatory caution -- you probably don't actually want to use shell script for this. 这是强制性的警告-您实际上可能不想为此使用shell脚本。 Please investigate more secure, more robust, more specialized alternatives. 请研究更安全,更可靠,更专业的替代方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM