How to get HTTP response body without headers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
favianee
Forum Newbie
Posts: 1
Joined: Fri Feb 25, 2005 11:07 am

How to get HTTP response body without headers

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

file_get_contents($url);
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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
Post Reply