开发者

viewing requests sent by curl

How can I see requests that are sent out by curl? For example;

I'm getting a page and print out the contents, 开发者_开发问答but this page also requests another page that I would like the contents of.

How would I do this?


If it's header information you're after...

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER,1);

and

curl_setopt($curl_handle, CURLOPT_HEADER,1);

will return the header information in the results which you will then have to process with either string functions or regular expressions.

eg

preg_match_all('#HTTP/\d\.\d.*?$.*?\r\n\r\n#ims', $curl_result, $header_matches);
$headers = split("\r\n", str_replace("\r\n\r\n", '', array_pop($header_matches[0])));
$curl_result = preg_replace('#HTTP/\d\.\d.*?$.*?\r\n\r\n#ims', '',$curl_result);

From there you can locate any offending header entries in the array $headers

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜