I have this strange problem that I'm receiving 400 Bad request as a response and I have absolutely no idea what's wrong with the header. Here's my code:
<?php
$sock = fsockopen('IP ADDRESS', 80, $errno, $errstr);
$header = array(
'GET / HTTP/1.1',
'Host: stackoverflow.com',
'User-agent: My Useragent',
'Connection: Close'
);
fputs($sock, join('\r\n', $header));
while(!feof($sock))
{
echo fgets($sock, 128);
break;
}
fclose($sock);
?>
Any ideas what I'm doing wrong?
Thanks
EDIT: Thanks to MrCode this problem was solved. Issue was here:
fputs($sock, join('\r\n', $header));
I had to change it to:
fputs($sock, join("\r\n", $header)."\r\n\r\n");
Notice double quotes and "\r\n\r\n"
Thanks again to MrCode