Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preview CURL request prior to sending it

Tags:

php

soap

curl

xml

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?

like image 646
bcmcfc Avatar asked Mar 16 '11 15:03

bcmcfc


People also ask

How do I show curl request?

We can use curl -v or curl -verbose to display the request headers and response headers in the cURL command. The > lines are request headers . The < lines are response headers .

What is Curl_getinfo?

curl_getinfo — Get information regarding a specific transfer.

What is curl_exec?

curl_exec(CurlHandle $handle ): string|bool. Execute the given cURL session. This function should be called after initializing a cURL session and all the options for the session are set.


2 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.

like image 184
Treffynnon Avatar answered Oct 19 '22 23:10

Treffynnon


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.

like image 23
Slava Avatar answered Oct 19 '22 23:10

Slava