HttpClient - PHP Web Client Class

Translation of the original in Catalan. Read it in: CatalàCastellano

This class lets us implement an HTTP 1.0 and 1.1 client in a very simple way, for both GET and POST requests. In fact, it does something similar to what I was saying about the perl class WWW:Mechanize, although with far fewer details. Even so it can be very useful to interact with other websites from our PHP code. What is more, using this class is very simple. HttpClient implements the following features.

  • Implements a useful subset of the HTTP 1.0 and 1.1 protocols.
  • Includes cookie support.
  • Ability to set the user agent and referal fields.
  • Can automatically handle redirected pages.
  • Can be used for multiple requests, with any cookies sent by the server resent for each additional request.
  • Support for gzip encoded content, which can dramatically reduce the amount of bandwidth used in a transaction.
  • Object oriented, with static methods providing a useful shortcut for simple requests.
  • The ability to only read the page headers - useful for implementing tools such as link checkers.
  • Support for file uploads.

For more information I recommend you look at the examples on the class's website, it is really simple to use.