Page 1 of 1

How to get HTTP response body without headers

Posted: Fri Feb 25, 2005 11:13 am
by favianee
Hi All,

I've been trying to retrieve HTTP response data using the following:

while(!feof){
$response[i++]=fgets($socket);
}

However this only allows me to get the data line by line. Unfortunately this method retrieves the header information before getting the actual data that I need in the HTTP response (i.e. the 'body'). Is there any way that I can retrieve the 'body' directly without having to read the header information first?

Thanks.

Posted: Fri Feb 25, 2005 11:14 am
by feyd
file_get_contents($url);

Posted: Fri Feb 25, 2005 9:50 pm
by timvw
after the headerst a \r\n is required. so you could read-and-skip untill there...

Code: Select all

// skip to end of headers
$skip = true;
while (!feof($fp) && $skip)
{
  $line = fgets($fp);
  if ($line == "\r\n")
  {
    $skip = false;
  }
}

// now you can read to feof