HTTP POST from PHP, without cURL


Wez have a new post on his blog on HTTP post from PHP without Curl. The code is using fopen() mixed with stream_context_create() to make post request, then stream_get_contents() to retrieve data. Headers are optional but if not set, Content-Type will be set automatically to application/x-www-form-urlencoded. Wez suggested also to look at the http_build_query() to assemble query/post parameters from a PHP vars.

I don’t think we do a very good job of evangelizing some of the nice things that the PHP streams layer does in the PHP manual, or even in general. At least, every time I search for the code snippet that allows you to do an HTTP POST request, I don’t find it in the manual and resort to reading the source. (You can find it if you search for “HTTP wrapper” in the online documentation, but that’s not really what you think you’re searching for when you’re looking).

Previous articleWho Aquired What
Next articleFirefox Windows Authentication
Hatem Ben Yacoub, Energy engineer, Entrepreneur, ICT & eGov consultant, ITIL v3 Certified, Certified Document Imaging Architect (CDIA+), Senior Systems architect, PHP expert and PHP5.3 ZCE, OpenGov/OpenData Advocate, and Open source Evangelist.