2

Here is what i have so far:

#!/bin/bash
if [ "$REQUEST_METHOD" = "POST" ]; then
    if [ "$CONTENT_LENGTH" -gt 0 ]; then
        read -n $CONTENT_LENGTH POST_DATA <&0
    fi
fi

I was told that with this script when you receive post request to http://127.0.0.1./test.sh it will read the post data. However when i try to make post request to this file i see it's content and nothing else is happening.

Is it even possible to receive HTTP POST request to /bin/bash/ script file and if so how ?

Venelin
  • 2,905
  • 7
  • 53
  • 117

2 Answers2

0

You should read until the end of package like this.

DONE=false
until $DONE ;do
read || DONE=true
echo $REPLY
done

Or like this:

in_raw="$(cat)" 
if [ "$REQUEST_METHOD" = "POST" ]; then
    echo "<p>Post Method</p>"
    if [ "$CONTENT_LENGTH" -gt 0 ]; then
    in_raw="$(cat)"  
    fi
fi
mnr
  • 83
  • 7
-2

Maybe you must configure the webserver to execute the script. If you use the Apache-Server then you must load the cgi-module. Its not loaded by default.