I have this strange problem: I get 400 Bad requests as an answer, and I absolutely do not understand what happened to the header. Here is 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?
thank
EDIT . Thanks to MrCode, this problem has been resolved. The problem was here:
fputs($sock, join('\r\n', $header));
I had to change it to:
fputs($sock, join("\r\n", $header)."\r\n\r\n");
Pay attention to double quotes and "\ r \ n \ r \ n"
Thanks again MrCode
Jason source
share