While browsing my Google Analytics, I got surprised how many people are still searching for CakePHP cURL solutions while CakePHP has it own build-in class (HttpSocket) with the very same functionality.
The main argument I hear for using cURL for your API requests, is because it has so many nice features. I like cURL and it helps me a lot, but I rather use what’s inside the CakePHP framework. HttpSocket has probably all the features you actually need and use. In this article I will show you how to refactor your app from cURL to CakePHP’s HttpSocket.
I will show some cURL vs HttpSocket examples for the following cases:
- Basic GET request
- Basic POST request
- HttpSocket Request with basic HTTP authentication
- HttpSocket Request with Cookies
- HttpSocket Request that allows self-signed SSL connections
- HttpSocket Request through a proxy
Basic GET request
Basic POST request
HttpSocket Request with basic HTTP authentication
HttpSocket Request with Cookies
HttpSocket Request that allows self-signed SSL connections
HttpSocket Request through a proxy
Some other quick fixes
So, what is your excuse to use cURL in your CakePHP project?