I have been trying to post data to a URL (https) but no luck. I'm using the following function.
Wondering if anything is wrong in this. Can someone please take a look ?
function post($data) {
$host = 'www.xxxxxxx.com';
$path = '/test/testform';
$http_response = '';
$content_length = strlen($data);
$fp = fsockopen($host, 443,$errno, $errstr);
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-Length: $content_length\r\n");
fputs($fp, $data);
fputs($fp, "Connection: close\r\n\r\n");
while (!feof($fp)) $http_response .= fgets($fp);
fclose($fp);
echo " hello...< $http_response ...> $data";
echo " ... $errno ... $errstr ...";
return $http_response;
}