<?php
function sendHTTP($reqBody, $host, $port, $wsPath) {
	$res = "";

	flush();

	try {
		//Paymorrow Server URL
		if (!$host) {
			// FOR DEV
			$host = "test.paymorrow.net";
		}

		if (!$port) {
			$port = 443;
		}

		if (!$wsPath) {
			// DEFERRED
			//$wsPath = '/perth/services/PaymorrowDeferredConfirmationService.Paymorrow';
			// DIRECT / IS THE DEFAULT
			$wsPath = "/perth/services/PaymorrowService.Paymorrow";
		}

		// HTTP Protocol settings for sending request
		$req = "POST ".$wsPath." HTTP/1.1\r\n"
				."Host: $host\r\n"
				."Content-Type: text/xml\r\n"
				."Content-Length: ".strlen($reqBody)."\r\n"
				."Connection: close\r\n\r\n"
				.$reqBody;

		flush();

		if (!($fp = fsockopen("ssl://".$host, $port, $errNo, $errStr))) {
			//echo "Cannot open:".$errStr;
			flush();

			return false;
		}

		//data placed on Stream
		fwrite($fp, $req, strlen($req));

		//Read data from Stream
		while($data = fread($fp, 32768)) {
			$res.=$data;
		}

		fclose($fp) ;

		flush();
	} catch (Exception $e) {
		//echo $e->getMessage();
	}
	
	flush();
	
	return $res;
}

/* EOF */