Home » Php » php – Preview CURL request prior to sending it

php – Preview CURL request prior to sending it

Posted by: admin July 12, 2020 Leave a comment

Questions:

I am sending an XML SOAP request via CURL in PHP.

Is there a way of viewing (print_r/var_dump) the entire request including headers before sending it?

How to&Answers:

See CURLOPT_VERBOSE. But I don’t think you will be able to get anything from it until the request has been completed.

curl_setopt($curl, CURLOPT_VERBOSE, true);

See the PHP manual page for curl_setopt() for the options.

Answer:

You can set curl_setopt($request, CURLINFO_HEADER_OUT, TRUE); and then after curl_exec($request); see the request sent with echo curl_getinfo($request, CURLINFO_HEADER_OUT). But it only works AFTER the request is sent. I don’t think it’s possible to get what is going to be sent before actually executing it.