问题
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