2013-03-21 178 views
2

虽然curl的下面的输出提供了有用的头信息,但它不提供有效负载信息。例如,我想在提供的调试信息中看到{“jason_index”,“json_value”}。php cURL CURLOPT_VERBOSE不显示有效负载

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 

$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); 
+0

如果你想记录你张贴'$ data':**简短的回答**详细的输出是或关闭,因此您必须编写一个自定义日志记录功能,以抓取STDERR数据和您的有效载荷数据,并以您所需的格式将其写入日志。 – 2014-03-06 23:20:59

+0

此答案有处理STDERR数据的方法:http://stackoverflow.com/questions/9550319/bad-request-connecting-to-sites-via-curl-on-host-and-system/9571305#9571305获取信息在 – 2014-03-06 23:24:58

回答

1

我最近碰到这个问题,只有我管理,看看到底是怎么回事的方法是使用代理服务器调试,如:

其他解决方案是使用数据包检查等(此选项不会让你看到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 
+0

似乎并不容易:(与Laravel我得到一个错误:在routes.php第60行异常:无法连接到本地端口8080:连接拒绝 – geoidesic 2017-01-26 15:38:16

+0

可能是因为我的代码是在一个流浪箱,而打嗝是在主机上运行。 – geoidesic 2017-01-26 15:45:53