如何在执行之前打印出确切的 cURL 请求,包括发布的字段

Jay*_*len 5 php api json curl

我正在尝试使用 cURL 调用与 API 进行通信。

我试图查看我发送到 API 的确切请求,“包括标题、正文和正在发布的字段”。我如何获得请求的副本?

我尝试使用,curl_getinfo但这并没有告诉我确切的请求。然后,我添加了一个代码来将请求打印到一个名为request.txt

这是我的代码,它工作正常,但没有显示正在发布的字段

function CallAPI($method, $url, $data = false, $header = array())
{
    $curl = curl_init();

    if(!empty($header)){
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    }
    $f = fopen('request.txt', 'w');
    //disable the use of cached connection
    curl_setopt($curl, CURLOPT_FRESH_CONNECT, TRUE);

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

    curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
    curl_setopt($curl, CURLOPT_FILE, $f);
    curl_setopt($curl, CURLOPT_INFILESIZE, $f);
    curl_setopt($curl, CURLOPT_STDERR, $f);

    switch ($method)
    {
        case "POST":
            curl_setopt($curl, CURLOPT_POST, 1);

            if ($data){
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            }
            break;
        case "PUT":
            curl_setopt($curl, CURLOPT_PUT, 1);
            break;
        default:
            if ($data){
                $url = sprintf("%s?%s", $url, http_build_query($data));
            }
    }   

    $result = curl_exec($curl);
    $info = curl_getinfo($curl);

    //print data
    echo '<pre>';
    print_r($info);
    echo '</pre>';
    curl_close($curl);

    fclose($f);

    return $result;
}

I am able to see something like this
* Hostname SERVERNAME was found in DNS cache
*   Trying INTERNAL IP...
* Connected to SERVERNAME (INTERNAL IP) port INTERNAL PORT (#0)
> POST /icws/connection HTTP/1.1
Host: SERVERNAME:INTERNAL PORT
Accept: */*
Accept-Language: en-US
Content-Length: 517
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------cb7489673677d758

* Done waiting for 100-continue
< HTTP/1.1 400 Bad Request
< Cache-Control: no-cache, no-store, must-revalidate
< Pragma: no-cache
< Expires: 0
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
< Content-Type: application/vnd.inin.icws+JSON; charset=utf-8
< Date: Mon, 04 May 2015 20:31:56 GMT
< Server: HttpPluginHost
< Content-Length: 79
* HTTP error before end of send, stop sending
< 
Run Code Online (Sandbox Code Playgroud)

我如何还包含随请求一起发送的字段?