CGI script, save `printf` to file using Terminal (OS X)

試著忘記壹切 提交于 2019-12-12 02:54:39

问题


I asked a question earlier about how to read a POST request with your own local server (On OS X)

Now my problem is that i can't save the POST Data received on my server.

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.

But how can i save the printf output?

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

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.

Basic roundup: I want to save the printf that contains the POST Request data to a file.


回答1:


I believe you are wanting this:

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...



来源:https://stackoverflow.com/questions/14762083/cgi-script-save-printf-to-file-using-terminal-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!