php cURL CURLOPT_VERBOSE不显示有效负载


php cURL CURLOPT_VERBOSE not showing payload

虽然curl的下面输出提供了有用的头信息,但它没有提供有效负载信息。例如,我希望在提供的调试信息中看到{"jason_index","json_value"}。

1)。是否可以使用详细模式内联显示有效负载?

2)。查看由cURL处理的发送负载的最佳方式是什么?

* About to connect() to domain.com port 443 (#0)
*   Trying IP... * connected
* Connected to domain.com (IP) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: /usr/share/curl/curl-ca-bundle.crt
  CApath: none
* SSL connection using RC4-SHA
* Server certificate:
*    subject: /serialNumber=SN/C=CA/ST=Ontario/L=Ottawa/O=ORG Inc./CN=*.domain.com
*    start date: 2010-05-10 22:23:08 GMT
*    expire date: 2015-08-12 19:17:14 GMT
*    subjectAltName: alt.domain.com matched
*    issuer: /C=US/O=Equifax/OU=CA
* SSL certificate verify ok.
* Server auth using Basic with user 'userid'
> POST request_uri.json HTTP/1.1
Authorization: Basic auth_string=
User-Agent: UA
Host: alt.domain.com
Accept: */*
Content-Type: application/json; charset=utf-8
Content-Length: 85
< HTTP/1.1 422 Unprocessable Entity
< Server: ServerName
< Date: Thu, 21 Mar 2013 20:08:56 GMT
< Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Status: 422 Unprocessable Entity
< 
* Connection #0 to host alt.domain.com left intact
* Closing connection #0

cURL语句示例

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, fopen(dirname(__FILE__) . "/headers.txt", "w+"));
$result = curl_exec($ch);

我最近遇到了这个问题,我设法看到正在发生的事情的唯一方法是使用调试代理,如:

  • 打嗝套件- Linux/Windows/Mac (Java)
  • fiddler - Windows

其他解决方案是使用数据包检查器,如(此选项不会让您看到HTTPS流量):

  • WireShark

使用代理的解决方案很容易设置,只需安装和使用:

curl_setopt($ch, CURLOPT_PROXY, 'localhost:8080'); // default for burp suite
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // ignore certs while connecting to https