Diego Slinger
Diego Slinger

Reputation: 149

cURL, PHP. How to output all headers and settings?

Is there a way how to output in a browser everything that curl is sending to the remote api url? Headers, settings just everything. I understand that in the shown code only $url and $headers are the data which transferred as the request. HTTPS is not used. I would like to go as i used a TCP sniffer for grabbing traffic.

$ch = curl_init();
$url = self::API_URL . $data['request']; // https://api.bitfinex.com/v1/account_infos

$headers = $this->prepare_header($data);

curl_setopt_array($ch, array(
    CURLOPT_URL             => $url,
    CURLOPT_POST            => TRUE,
    CURLOPT_RETURNTRANSFER  => TRUE,
    CURLOPT_HTTPHEADER      => $headers,
    CURLOPT_SSL_VERIFYPEER  => TRUE,
    CURLOPT_CONNECTTIMEOUT  => self::CONNECT_TIMEOUT,
    CURLOPT_POSTFIELDS      => ''
));

Upvotes: 0

Views: 2460

Answers (1)

hanshenrik
hanshenrik

Reputation: 21483

there is no (feasable) way to get all active settings, the closest you can get is var_dump(curl_getinfo($ch)); - as for dumping all headers, do curl_setopt($ch,CURLOPT_VERBOSE,1);, this will dump both all outgoing and incoming headers, but be aware that due to PHP bug #65348, setting CURLOPT_VERBOSE will break CURLINFO_HEADER_OUT.. (you can work around it by parsing the VERBOSE output, but it aint pretty)

Upvotes: 1

Related Questions