I am using these to get the code of a page that is listed in the code below. I am using the example code of fsockopen on php.net as reference. I can get the response header but i have a problem with the CHUNKs.


the Code :


$header = "";
$response = "";


if (!($fp = fsockopen ("myplanetside.station.sony.com", 80, $errno, $errstr,30)))
exit($errstr);
else {
echo "bin drin ";

echo "Bin richtig";
fputs ($fp, "GET /outfit.jsp?outfitId=6607&worldId=21 HTTP/1.1 \r\n");
fputs ($fp, "Host: myplanetside.station.sony.com\r\n");
fputs ($fp, "Connection: close\r\n");
fputs ($fp, "Accept-Encoding: gzip\r\n");
fputs ($fp, "Accept: application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1\r\n");
fputs ($fp, "Accept-Language: en-us,en;q=0.5\r\n");
fputs ($fp, "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n");
fputs ($fp, "Accept-Language: en-us,en;q=0.5\r\n\r\n");


do $header.=fread($fp,1); while (!preg_match('/\\r\\n\\r\\n$/',$header));



// check for chunked encoding
if (preg_match('/Transfer\\-Encoding:\\s+chunked\\r\\n/',$header)){
echo "bin in der IF alls TRUE";
do {
$byte = "";
$chunk_size="";
do {
// Here should be the the Problem
// I get endles query so to say.
$chunk_size.=$byte;
$byte=fread($fp,1);
} while ($byte!="\\r"); // till we match the CR
fread($fp, 1); // also drop off the LF
$chunk_size=hexdec($chunk_size); // convert to real number
$response.=fread($fp,$chunk_size);
fread($fp,2); // ditch the CRLF that trails the chunk
} while ($chunk_size); // till we reach the 0 length chunk (end marker)
}//end if
else {
// check for specified content length
if (preg_match('/Content\\-Length:\\s+([0-9]*)\\r\\n/',$header,$matches)) {
$response=fread($fp,$matches[1]);
} else {
// not a nice way to do it (may also result in extra CRLF which trails the real content???)
while (!feof($fp)) $response .= fread($fp, 4096);
}
}
// close connection
fclose($fp);
}


// do something useful with the response
print($header);
print($response);

hope someone can help me ...

P.S. : Sorry for the bad eng.

mfG Munir

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to