teepusink
teepusink

Reputation: 28892

HOWTO observe network traffic for curl debugging

I'm trying to make a curl call that also pass an image file along.
Obviously it's not working for me. However, I've got a test working that just use straight up html form.

How can I debug / print out the raw data that is being passed from curl?
Trying to compare the call with the form version to see what is different.

I've tried these:

curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, true);

print_r(curl_getinfo($curl));

But those seems to just return the response as opposed the raw request. (it's through a 3rd party so I have no access to the end point)

Thank you,
Tee

Upvotes: 5

Views: 4634

Answers (3)

teepusink
teepusink

Reputation: 28892

This one helped me debug it. Doesn't print the entire thing, but did print the header which was super helpful.

curl_setopt($curl, CURLINFO_HEADER_OUT, true);

Thanks,
Tee

Upvotes: 1

Frederic Bazin
Frederic Bazin

Reputation: 1529

see previous answer on stackoverflow for similar question.

Use wireshark to observe network traffic and add a filter 'ip.addr == x.x.x.x' with the IP of the target website.

Upvotes: 0

mario
mario

Reputation: 145482

curl the command line client has a --trace-ascii option for that. But that feature is not exposed in the PHP interface.

The _VERBOSE output might however still contain some information (if it's really a server error). You must redirect it into a separate file however before:

$fp = fopen("curl.log", "w");
curl_setopt($ch, CURLOPT_STDERR, $fp);

Failing that, I'm afraid the best option is to peek at the network traffic (using a separate tool, ad-hoc proxy maybe).

Upvotes: 1

Related Questions