I'd like to see what the post fields in the request are before I send it. (For debugging purposes).
The PHP library (class) I am using is already made (not by me), so I am trying to understand it.
As far as I can tell, it uses curl_setopt()
to set different options like headers and such and then it uses curl_exec()
to send the request.
Ideas on how to see what post fields are being sent?
Another (crude) option is to utilize netcat for dumping the full request:
And of course sending the failing request to it:
Notably that will always hang+fail, since netcat won't ever construct a valid HTTP response. It's really just for inspecting what really got sent. The better option, of course, is using a http request debugging service.
You can enable the
CURLOPT_VERBOSE
option and log that information to a (temporary)CURLOPT_STDERR
:You can then read it after curl has done the request:
(I originally answered similar but more extended in a related question.)
More information like metrics about the last request is available via
curl_getinfo
. This information can be useful for debugging curl requests, too. A usage example, I would normally wrap that into a function:Here is a simpler code for the same:
where $fp is a file handle to output errors. For example:
( Read on http://curl.haxx.se/mail/curlphp-2008-03/0064.html )
You can enable the
CURLOPT_VERBOSE
option:When
CURLOPT_VERBOSE
is set, output is written to STDERR or the file specified usingCURLOPT_STDERR
. The output is very informative.You can also use tcpdump or wireshark to watch the network traffic.
Here is an even simplier way, by writing directly to php error output
To just get the info of a CURL request do this: