Darryl Hein
Darryl Hein

Reputation: 145107

How do I find out what was sent with cURL?

I'm trying to figure out why a cURL process (written in PHP) that used to be working is no longer working. I'm receiving the same data back as what an actual browser is receiving, but I'm not sure if I'm sending the same information as the browser.

Is there a way I can find out what the cURL library in PHP is sending?

Note: I don't have access to the server I'm accessing and I'm actually thinking they're blocking me, so I'm trying to determine what I need to change to copy the browser.

Upvotes: 2

Views: 538

Answers (2)

James Zaghini
James Zaghini

Reputation: 4011

After you run the curl, try this:

$info = curl_getinfo($curlHandle);
echo '<pre>';
print_r($info);
echo '</pre>';

There's a complete list of what curl_getinfo returns here: https://www.php.net/manual/en/function.curl-getinfo.php

One of which is: CURLINFO_HEADER_OUT - The request string sent

Hope that does it for ya :D

Upvotes: 1

timdev
timdev

Reputation: 62914

Since PHP 5.1.3, you can use CURLOPT_HEADER_OUT to get the request headers you sent. I think this might be what you're looking for.

<?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));

Upvotes: 3

Related Questions