#!/usr/bin/perl # # Server side program to receive posted data from http client # $logfile = './logfile.txt'; # Log file $acc = 0; if ($ENV{'REQUEST_METHOD'} eq 'POST') { # POST request? $len = $ENV{'CONTENT_LENGTH'}; if ($len > 1000) { $len = 1000; } binmode STDIN; read(STDIN, $buff, $len); } elsif ($ENV{'REQUEST_METHOD'} eq 'GET') { # GET request? $buff = $ENV{'QUERY_STRING'}; $len = length($buff); } if ($len > 0 && open(WHA, ">> $logfile")) { # Open log file for append binmode WHA; print WHA "$buff\r\n"; close(WHA); $acc = 1; } print "Content-Type: text/plain; charset=utf-8\r\n"; print "\r\n"; if ($acc) { print "Thanks!\n"; } else { print "Oops!\n"; } exit;