开发者

PHP - stripout header

I've made a proxy system with CURL. I do need to access the header, but I also want to be able to separate the header from the content.

All was working fine until I ran into that response:

HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Date: Wed, 23 Mar 2011 15:36:57 GMT
Server: Apache/2.2.16 (Ubuntu)
X-Powered-By: PHP/5.3.3-1ubuntu9.3
Expires开发者_开发技巧: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

<h1>Gestion des actualitées</h1>

I try to separate the header from the content using:

strpos($httpResponse, "\r\n\r\n");

But the problem is that this will cut the header right after the "100 Continue". Note that I don't create the header, it's a default behavior of Apache...

Do you have a good way to separate the header from the content ?


Based on the brian_d idea, I've come up with:

$httpResponse = curl_exec($ressource);
$headerLength = curl_getinfo($ressource,CURLINFO_HEADER_SIZE);
$headers = substr($httpResponse, 0, $headerLength);
$content = substr($httpResponse, $headerLength);

I think that's ok...


Try altering the request to include Content-Length.

$content_length = //parse field  
$total_length = strlen($httpResponse);  
$body = substr($httpResponse, $total_length - $content_length); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜