6

I'm having dificulties to query a webform using CURL with a PHP script. I suspect, that I'm sending something that the webserver does not like. In order to see what CURL realy sends I'd like to see the whole message that goes to the webserver.

How can I set-up CURL to give me the full output?

I did

curl_setopt($ch, CURLOPT_VERBOSE, TRUE);

but that onyl gives me a part of the header. The message content is not shown.

4 Answers 4

3

Thanks for all the answers! After all, they tell that It's not possible. I went down the road and got familiar with Wireshark. Not an easy task but definitely worth the effort.

Sign up to request clarification or add additional context in comments.

1 Comment

Wireshark won't help if you are request https endpoint because the data is encrypted.
1

Have you tried CURLINFO_HEADER_OUT?

Quoting the PHP manual for curl_getinfo:

CURLINFO_HEADER_OUT - The request string sent. For this to work, add the CURLINFO_HEADER_OUT option to the handle by calling curl_setopt()

4 Comments

Well as the manual correctly says: headers only. But I'm in need of the whole thing, header and contents.
Why not just POST the thing to some other address and debug? If cURL really screws something up, it might as well lie anyway.
Plus, it is much more probable to be about headers. Given that you want to post a webform (on some site you don't control, I'm guessing), are you sure it's not a cookies issue? Or User-Agent for example. Or something else. Why don't you post your whole code and maybe we can diagnose the problem faster that way.
That would of course be an other god way to get help. Since I'm kind of the web service guy in our company I'd like to be able to debug CURL when things go wrong.
-1

If you are wanting the content can't you just log it? I am doing something similar for my API calls

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, self::$apiURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, count($dataArray));
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);

$logger->info("Sending " . $dataString);
self::$results = curl_exec($ch);
curl_close($ch);

$decoded = json_decode(self::$results);
$logger->debug("Received " . serialize($decoded));

Or try

curl_setopt($ch, CURLOPT_STDERR, $fp);

2 Comments

That's not what I'm looking for. I can check my variables with XDebug, no problem. I want to see the whole HTTP request, header and contents as it is sent by CURL.
@BetaRide As far as I know it isn't possible to see the entire contents without using WireShark or a tcpdump. The closest you can get is displaying the headers and content together.
-2

I would recommend using curl_getinfo.

<?php 
curl_exec($ch); 
   $info = curl_getinfo($ch); 
       if ( !empty($info) && is_array($info) { 
          print_r( $info ); 
          } else { 
                  throw new Exception('Curl Info is empty or not an array');
       };
 ?>

1 Comment

This only shows a lot of details about the response. What I need is all details about request (i.e. what goes to the webserver).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.