php cURL CURLOPT_VERBOSE 不显示负载

标签 php debugging curl payload verbose

虽然 curl 的以下输出提供了有用的 header 信息,但它不提供负载信息。例如,我希望在提供的调试信息中看到 {"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);

最佳答案

我最近遇到了这个问题,我设法查看发生了什么的唯一方法是使用调试代理,例如:

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

带有代理的解决方案易于设置,只需安装和使用:

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

关于php cURL CURLOPT_VERBOSE 不显示负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15558520/

相关文章:

php - 在 laravel 中处理登录尝试次数太多?

php - 同一页面上的 Ajax 到 PHP

python - 无法在 VScode 中调试 Python

c - 如何使用 makefile 调试项目

c++ - 使用 curl 下载文件时确定扩展名?

php - 使用 cURL 登录到特定的 WordPress 页面

PHP PDO-MYSQL : How to use database connection across different classes

javascript - 使用链接调用 ajax 函数

javascript - Heroku 上的 Meteor 应用程序 sockjs 连接已关闭

linux - 使用 cURL 命令从 SFTP 服务器获取 .listing 文件的命令是什么