2013-03-21 182 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