PHP - Debugging Curl

后端 未结 8 1450
無奈伤痛
無奈伤痛 2020-11-21 11:35

I\'d like to see what the post fields in the request are before I send it. (For debugging purposes).

The PHP library (class) I am using is already made (not by me),

8条回答
  •  滥情空心
    2020-11-21 11:50

    Output debug info to STDERR:

    $curlHandler = curl_init();
    
    curl_setopt_array($curlHandler, [
        CURLOPT_URL => 'https://postman-echo.com/get?foo=bar',
        CURLOPT_RETURNTRANSFER => true,
    
        /**
         * Specify debug option
         */
        CURLOPT_VERBOSE => true,
    ]);
    
    curl_exec($curlHandler);
    
    curl_close($curlHandler);
    

    Output debug info to file:

    $curlHandler = curl_init();
    
    curl_setopt_array($curlHandler, [
        CURLOPT_URL => 'https://postman-echo.com/get?foo=bar',
        CURLOPT_RETURNTRANSFER => true,
    
        /**
         * Specify debug option.
         */
        CURLOPT_VERBOSE => true,
    
        /**
         * Specify log file.
         * Make sure that the folder is writable.
         */
        CURLOPT_STDERR => fopen('./curl.log', 'w+'),
    ]);
    
    curl_exec($curlHandler);
    
    curl_close($curlHandler);
    

    See https://github.com/andriichuk/php-curl-cookbook#debug-request

提交回复
热议问题