Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view PHP cURL request body (like CURLINFO_HEADER_OUT for headers)

Tags:

php

curl

I can view the headers of a request sent using php curl with the following:

curl_getinfo($ch, CURLINFO_HEADER_OUT);

I wish to see the body of what is being sent out as well but cannot for the life of me find any way to do so.

like image 636
thedarklord47 Avatar asked Dec 18 '15 03:12

thedarklord47


People also ask

How do I view cURL headers?

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 .

How do I view response headers in PHP?

Response Headers in cURLBy setting the CURLOPT_HEADER and CURLOPT_NOBODY options to true, the result of curl_exec() will only contain the headers. This is useful when you only need the headers, but most of the time, we need the content of the request too. The solution to this lies in the CURLOPT_HEADER option as well.

How do you use the cURL command with headers?

To send an HTTP header with a Curl request, you can use the -H command-line option and pass the header name and value in "Key: Value" format. If you do not provide a value for the header, this will remove the standard header that Curl would otherwise send. The number of HTTP headers is unlimited.


1 Answers

I was unable to find any such option after extensively searching the PHP cURL documentation.

My solution was to use the web proxy tool Charles

Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. This includes requests, responses and the HTTP headers (which contain the cookies and caching information).

like image 95
thedarklord47 Avatar answered Sep 17 '22 03:09

thedarklord47