0

I am trying to login to a website from a Command. I would like to inspect what headers are sent to the site so that I can compare them with what the browser sends. I am ASSuming the Cake Http Client will send some headers by default, I want view these.

I have been able to see the response headers via $this->Client->get($url)->getHeaders(), but have found no way to see what headers are sent.

Heath
  • 13
  • 3
  • I haven't tried this, but from looking at the code it seems that maybe just `$this->Client->getHeaders()` might work? – Greg Schmidt Jun 28 '23 at 19:24
  • Does not work: `2023-06-28 19:49:45 error: [Error] Call to undefined method Cake\Http\Client::getHeaders()` – Heath Jun 28 '23 at 19:50
  • What's your exact CakePHP version (last line in lib/Cake/VERSION.txt or vendor/cakephp/cakephp/VERSION.txt)? – Greg Schmidt Jun 28 '23 at 23:42
  • The version is 4.4.10 – Heath Jun 29 '23 at 01:07
  • Right, the `getHeaders` is on the request object, not the client, and it seems that the request is only ever a temporary internal implementation detail. It looks like you might be able to make your own custom Client, extending the default one, overriding just the `_createRequest` function to call the default and store it in the Client object, and exposing a method to retrieve the headers from that. – Greg Schmidt Jun 29 '23 at 14:57
  • Or if you need this only temporarily during debugging of your code, just throw something into the Cake code that logs the headers when it sends a request, or use `xdebug` to put a breakpoint and inspect the data at that time. – Greg Schmidt Jun 29 '23 at 14:58

0 Answers0