So I'm currently trying to implement the 'SendToHost' function that is widely used for 'GET' and 'POST' procedures. In my case, I want to use it for sending a 'postcode' to a shopping website's postcode input form for use with retrieving that postcode's specific catalogue. More specifically, the code should automatically generate the web page that has the results for the postcode. Below is my code coupled with the function and I'd like to know why it isn't working:
function SendToHost($host, $method, $path, $data, $useragent=0)
{
// Supply a default method of GET if the one passed was empty
if (empty($method))
$method = 'GET';
$method = strtoupper($method);
$fp = fsockopen($host,80);
if ($method == 'GET')
$path .= '?' . $data;
fputs($fp, "$method $path HTTP/1.1\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: " . strlen($data) . "\n");
if ($useragent)
fputs($fp, "User-Agent: MSIE\n");
fputs($fp, "Connection: close\n\n");
if ($method == 'POST')
fputs($fp, $data);
while (!feof($fp))
$buf .= fgets($fp,128);
fclose($fp);
return $buf;
}
echo sendToHost('catalog.coles.com.au','get','/default.aspx','ctl00_Body_PostcodeTextBox=4122');