PEAR2::HTTP Request
From PEAR Wiki
PEAR2::HTTP_Request provides the ability to make requests to http servers. It automatically picks the best backend to use.
Contents |
[edit] API Overview
This API is currently being reviewed, your feedback is welcomed either in emails to pear-dev or too josh@bluga.net or in the discussion page
[edit] HTTP_Request
The main entry point is the HTTP_Request class
$request = new HTTP_Request();
The constructor optionally takes a $uri parameter and a $adapter (instance of HTTP_Request_Adapter)
$request = new HTTP_Request('http://pear.php.net');
$request = new HTTP_Request('http://pear.php.net',new HTTP_Request_Adapter_Curl());
You interact with it by setting properties (exposed by __get/__set) or using a couple different methods
Properties
- uri - Uri to make a request too, a PEAR2_HTTP_Request_Uri object is created on set
- url - alias of uri
- verb - HTTP verb (GET/POST/HEAD/etc)
- body - Payload to send with the request (if an array is passed in it is automatically encoded, verb is set to POST, Content-Type is set too application/x-www-form-urlencoded)
- content - alias of body
- requestTimeout - Integer # of seconds to wait for the initial connection to be made
- proxy - Uri of the proxy server a PEAR2_HTTP_Request_Uri object is created on set
Methods
- setHeader($header,$value) - adds a header to the requests
- attach($listener) - attach an instance of PEAR2_HTTP_Request_Listener which gets status messages
- detach($listener) - detach an instance of PEAR2_HTTP_Request_Listener
- sendRequest() - make the request and return and HTTP_Request_Response instance
- requestToFile($file) - make the request writing the response body to $file, returns an HTTP_Request_Response instance with no body, optomizes memory use on large downloads if possible with the given adapter
[edit] HTTP_Request_Response
svn write me
[edit] HTTP_Request_Uri
svn write me
[edit] HTTP_Request_Headers
[1] write me
[edit] HTTP_Request_Listener
svn write me
[edit] Exceptions
svn Currently only has a single generic exception, chances are this needs to change
