0

I am using PHP and cURL to send in HTTP request to a REST API. However, I need to validate some data going in/out.

How can I get a copy of the entire request logged into a file?

I have added this line to my request

curl_setopt($ch, CURLOPT_VERBOSE, true);

I am hoping I can get a copy to look like this saves to a log file.

--- START REQUEST
POST /icws/3048186002/interactions/3002853105 HTTP/1.1
Host: servername:8018
Accept: */*
Cookie: icws_3048186002=64425290-29e5-432a-9ee1-c303cdee1f79
ININ-ICWS-CSRF-Token: WAp3cmF0Y2xpZmZlWBJJQ1dTLUFQSS1jb25uZWN0b3JYJGQwYjhlMWRhLTZlOTktNGIwMC05NGNlLTY5MDdkZjUwOWI5Y1gJMTAuMC40LjE4
ININ-ICWS-Session-ID: 3048186002
Content-Type: application/json
Content-Length: 35

{"attributes":{"logged":1}}
--- END REQUEST


--- START RESPOND
HTTP/1.1 200 OK
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: Wed, 02 Sep 2015 20:39:26 GMT
Server: HttpPluginHost
Content-Length: 0
--- END RESPOND

How can I capture this data without having to use WireShark? I would think cURL and PHP are advanced enough to allow you to log such a thing.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Junior
  • 11,602
  • 27
  • 106
  • 212
  • Curl does not provide any log tools. But some libraries like Guzzle for example provide an easy way to call external URLs. Those libraries often provide middlewares / subscribers. Guzzle for example supports middleware and you can find a middleware for monolog on github. – Michaël Garrez Sep 03 '15 at 15:58
  • Have you considered using T-Shark? (That is with the assumption that you like Wireshark but don't want to use a GUI) – pyRabbit Sep 18 '15 at 14:51

0 Answers0