开发者

PHP, curl, and raw headers

开发者 https://www.devze.com 2022-12-13 11:54 出处:网络
When using the PHP curl functions, is there anyway to see the exact raw headers that curl is sending to the serve开发者_StackOverflow中文版r?You can use curl_getinfo:

When using the PHP curl functions, is there anyway to see the exact raw headers that curl is sending to the serve开发者_StackOverflow中文版r?


You can use curl_getinfo:

Before the call

curl_setopt($ch, CURLINFO_HEADER_OUT, true);

After

$headers = curl_getinfo($ch, CURLINFO_HEADER_OUT);


<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_exec($ch);
var_dump(curl_getinfo($ch,CURLINFO_HEADER_OUT));
?>

Only available in php 5.1.3 http://php.net/manual/en/function.curl-getinfo.php


You can verify that they are the same by using your console and hitting

curl http://example.com/ -I

or

curl --trace-ascii /file.txt http://example.com/


AFAIK, the PHP/CURL binding still lacks proper support for CURLOPT_DEBUGFUNCTION which is a callback from libcurl that can provide all those details.

That's the primary reason why I recommend people to work out HTTP scripting things with the curl command line tool and its --trace-ascii option FIRST, then translate that into a PHP function.


be sure to set the CURLINFO_HEADER_OUT option before making the curl_getinfo call

curl_setopt($c, CURLINFO_HEADER_OUT, true);

0

精彩评论

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