View cURL request headers with POST data

How to view full request headers , including post data , using libcurl in php?

I am trying to simulate a page message which, when it is made from a browser and viewed in Live HTTP Headers, looks like this:

https://###.com POST /###/### HTTP/1.1 Host: ###.###.com ...snipped normal looking headers... Content-Type: multipart/form-data; boundary=---------------------------28001808731060 Content-Length: 697 -----------------------------28001808731060 Content-Disposition: form-data; name="file_data"; filename="stats.csv" Content-Type: text/csv id,stats_id,scope_id,stat_begin,stat_end,value 61281,1,4,2011-01-01 00:00:00,2011-12-31 23:59:59,0 -----------------------------28001808731060 Content-Disposition: form-data; name="-save" Submit -----------------------------28001808731060-- 

So, we can clearly see the file I'm downloading, this is the content, everything is there. But all my attempts to get data from cURL when I try to make the same post from php (using CURLOPT_VERBOSE or CURLINFO_HEADER_OUT ) display request headers that do not have mail data, for example:

 POST /###/### HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 Host: ###.###.com ...snipped normal-looking headers... Content-Length: 697 Content-Type: multipart/form-data; boundary=----------------------------e90de36c15f5 

Based on the Content-Length here, everything seems to be going well, but that would really help my debugging efforts to see the full request. I am also annoyed that it is difficult; I must be able to see all this; I know that something is missing me.

--- EDIT ---

What I'm looking for is equivalent to this :

 curl --trace-ascii debugdump.txt http://www.example.com/ 

which is apparently available with the CURLOPT_DEBUGFUNCTION option in libcurl but not implemented in php. Boo.

+7
source share
2 answers

You submit multipart / formdata. I think cURL basically shows the HTTP header. The "problem" is that multipart / formdata consists of several parts. This is above the "first level HTTP headers" and the body part of the "main HTTP body".

I do not know your environment, but you can debug and monitor TCP traffic. You can use Wireshark or tcpdump for this - Wireshark can also show dump files created by tcpdump.

+1
source

I needed to do just that, but I needed to check the connection with the bank.

It is very simple to use Fiddler2, enable decryption of HTTPS traffic and use cURL for Fiddler2 as a proxy for debugging in this situation:

 $proxy = '127.0.0.1:8888'; curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); 
+5
source

All Articles