PHP Classes

response

Recommend this page to a friend!

      PHP HTTP protocol client  >  All threads  >  response  >  (Un) Subscribe thread alerts  
Subject:response
Summary:response length
Messages:5
Author:Romans
Date:2005-09-11 12:28:46
Update:2006-04-18 17:30:04
 

  1. response   Reply   Report abuse  
Picture of Romans Romans - 2005-09-11 12:28:47
Hello,as i understand by the default, response is splitted. How to read response without splitting? coz i use substr and strpos next. It looks like:

//test_http.php

for(;;)
{
$error=$http->ReadReplyBody($body,1000);
if($error!=""
|| strlen($body)==0)
break;

if(strpos($body,'test')!==false)
{
$m1=strpos($body,"test")+10;
$m2=strpos($body,'test2',$m1);
$result=substr($body,$m1,$m2-$m1);
}
...
// echo HtmlSpecialChars($body);

}


... sometimes i can got result,sometimes not... coz can't find $m1 or $m2 position...

  2. Re: response   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2005-09-11 17:19:20 - In reply to message 1 from Romans
You can always read the whole response at once specifying a large enough length value to the ReadReplyBody function.

You can try checking the response header content-length. If it exists, it should return the length of the page. Otherwise, specify a very large value, larger that the expected page length.

Alternatively, you can read the page in fixed size chunks and keep concatenating in your output string variable.

  3. Re: response   Reply   Report abuse  
Picture of Romans Romans - 2005-09-12 19:14:08 - In reply to message 2 from Manuel Lemos
Thx for the answer...

I was trying to specify a very large value to the ReadReplyBody function, anyway if the body lenght is more then 100000 in my example(157852)and the "very large value" is 200000 the response is splitted ;(

  4. Re: response   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2005-09-12 20:00:21 - In reply to message 3 from Romans
If you specify a value larger than the content length, it should return all the data at once, not split in parts.

  5. Re: response   Reply   Report abuse  
Picture of David Torres David Torres - 2006-04-18 17:30:04 - In reply to message 4 from Manuel Lemos
I had an issue with the readReplyBody method not returning the full body that took me some time to figure out. Here is my solution in the hopes that it will clarify things for another user:

$readlen = 1000000;

for(;;){
$error = $http->ReadReplyBody($body,$readlen);
if($error != "" || strlen($body)==0) break;
$full_body .= $body;
}

echo htmlspecialchars($full_body);