问题描述
我之前问过一个关于如何读取 POST 请求的问题
使用您自己的本地服务器(在 OS X 上)
I asked a question earlier about how to read a POST request
with your own local server (On OS X)
现在我的问题是我无法保存在我的服务器上收到的 POST 数据.
Now my problem is that i can't save the POST Data received on my server.
我目前使用 while true;do nc -l 10000 接收并显示从我的 iOS 设备发送的 POST 消息,它运行良好.
I currently use while true; do nc -l 10000 < /dev/null ; printf '\n\n\n'; done
to receive and display the POST Message sent from my iOS device, and it workes perfectly.
但是我如何保存 printf
输出?
But how can i save the printf
output?
我尝试使用本地 .sh
文件并使用以下代码发送 POST 请求
(没有成功):
I tried using a local .sh
file and send the POST Request
withe the following code (with no success):
#!/bin/sh
printf 'Content-type: text/plain\r\n\r\n'
cat > /MYPATH/post-data
echo OK
我也尝试直接从终端保存文件(也没有成功):
I also tried to save the file directly from Terminal (also without success):
while true; do nc -l 10000 < /dev/null ; printf 'Content-type: text/plain\r\n\r\n' >> /MYPATH/post-data echo OK; done
然而,我在终端中使用的代码实际上创建了 post-data
文件,但只有 Content-type: text/plain
文本,而不是实际的 POST(终端显示帖子).
However the code I used in Terminal actually created the post-data
file, but only with the Content-type: text/plain
text, and not the actual POST (Terminal displayed the post tho).
我需要今晚回答这个问题,所以如果你能帮助我解决这个问题,我将不胜感激.
I need this answered tonight, so I would really appreciate it if you could help me on this one.
基本综述:我想将包含 POST 请求数据的 printf
保存到文件中.
Basic roundup: I want to save the printf
that contains the POST Request data to a file.
推荐答案
我相信你会想要这个:
while true; do (printf 'Content-type: text/plain\r\n\r\n'; nc -l 10000 < /dev/null) >> /MYPATH/post-data; echo OK; done
不确定您想要哪一侧的内容类型...
Not sure which side you want the Content-type on...
这篇关于CGI 脚本,使用终端 (OS X) 将 `printf` 保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!