PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 18, 2022

[FIXED] Under what circumstances will Cake3's HTTP Client return a NULL response?

 February 18, 2022     cakephp, cakephp-3.0     No comments   

Issue

I'm trying to connect to an API using Cake's HTTP Client. But the response object that is returned is null, no status code, no body, nothing, just null. It's worth noting that if I visit the URL from a browser I get the desired results.

I asked a question to see if I was doing anything stupid which is here. Judging by the lack of responses I dont think I have any silly syntax errors.

So now I'm wondering what has to happen for the Cake3 HTTP Client to return NULL rather than a response object? Hopefully knowing what could be going wrong will show me where to look.


Solution

Under what circumstances will Cake3's HTTP Client return a NULL response?

When the adapter returns an empty array (ie no response objects), or a non-array value. The client uses array_pop() on the adapters return value, which would return null in case of an empty array, or a non-array value.

In order to debug the problem, dig into the adapter code and check where things are going wrong. Unless you are using a custom adapter, that would be \Cake\Network\Http\Adapter\Stream::_send().

  • .../src/Network/Http/Adapter/Stream.php#L258-L277
  • .../src/Network/Http/Adapter/Stream.php#L94-L110

The response being malformed, like not containing a HTTP/... header could for example be one reason for such a failure. Maybe what you have there isn't a response at all, maybe the request didn't even made it through your firewall or something, but didn't caused an error. So, I'd suggest starting with inspecting $meta and $content and going from there.



Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing