Search code examples
phpcurlrequestheaderlibcurl

Show Curl POST Request Headers? Is there a way to do this?


I'm building a Curl web automation app and am having some issue with not getting the desired outcome of my POST action, I am having some trouble figuring out how I can show the full POST request I am sending over (with headers), I have been searching on this but everything that comes up is the response headers, actually I want these too but also the request, which none of the posts I find on google seem to mention..

I know I can display the result of a curl request using something like this (forgive me if my syntax is off, I already shut down my virtual machine with my ide and code to refer to

 $result = curl($curl_exect) ;

Anyways, I would greatly appreciate any advice on how to view the full headers, thanks


Solution

  • You can see the information regarding the transfer by doing:

    curl_setopt($curl_exect, CURLINFO_HEADER_OUT, true);
    

    before the request, and

    $information = curl_getinfo($curl_exect);
    

    after the request

    View: http://www.php.net/manual/en/function.curl-getinfo.php

    You can also use the CURLOPT_HEADER in your curl_setopt

    curl_setopt($curl_exect, CURLOPT_HEADER, true);
    
    $httpcode = curl_getinfo($c, CURLINFO_HTTP_CODE);
    
    return $httpcode == 200;
    

    These are just some methods of using the headers.