The cHttpRequest classes are a collection of classes to deal with HTTP requests. This is useful if your plugins or modules need to get data from an external service.
CONTENIDO is able to utilize cURL or PHP sockets to perform an HTTP request. The class cHttpRequest hides the differences between the two from the developer. You can let CONTENIDO choose which method to use:
To perform the actual request you have to use the request function:
The output variable now contains the body of the HTTP response.
Often it is required to send POST requests to other servers. You can do this by adding POST parameters to the object:
Every functions starting with "set" returns a reference to the object itself so that you can chain functions like shown above.
The request function will always use the POST method if any POST parameters were added to the object and GET otherwise. If you need a specific method you can use
All request functions have two boolean parameters. By default they return only the body of the response. If you do not care about the response and only want to know if the request was successful or not, you can use
If you need to read the headers of the response yourself you can use
The class also supports adding custom HTTP headers. Be careful with this though, since some headers might make the server act in an unexpected way!
Force the usage of cURL/sockets
Since both classes inherit from the base cHttpRequest classes you can use them directly in your code too.
The public interface is at the same for both of them. The cHttpRequestCurl class has two extra methods though:
Be careful though! cURL might not be available on all systems, so it is better to use the cHttpRequest class itself.