- make request_exec() always succeed (picky curl)
[m6w6/ext-http] / docs / examples / tutorial.txt
index d8d9fad84581dd48afd41703bc5d456f5feaf6f9..fbe9f210758fc659d7bdec23bbd57f5fcf083dd6 100644 (file)
@@ -12,11 +12,12 @@ $Revision$
        read from and written to a file.
 
 <?php
-$r = new HttpRequest('http://www.google.com');
+$r = new HttpRequest('http://www.google.com/search');
 
 // store Googles cookies in a dedicated file
+touch('google.txt');
 $r->setOptions(
-       array(  'cookiestore'   => '../cookies/google.txt',
+       array(  'cookiestore'   => 'google.txt',
        )
 );
 
@@ -27,7 +28,7 @@ $r->setQueryData(
 );
 
 // HttpRequest::send() returns an HttpMessage object
-// of type HttpMessage::RESPONSE or throws an exception
+// of type HttpMessage::TYPE_RESPONSE or throws an exception
 try {
        print $r->send()->getBody();
 } catch (HttpException $e) {
@@ -44,7 +45,7 @@ try {
        redirect option.
 
 <?php
-$r = new HttpRequest('http://dev.iworks.at/.print_request.php', HTTP_POST);
+$r = new HttpRequest('http://dev.iworks.at/.print_request.php', HTTP_METH_POST);
 
 // if redirects is set to true, a single redirect is allowed;
 // one can set any reasonable count of allowed redirects
@@ -61,6 +62,7 @@ $r->setPostFields(
        )
 );
 // add the file to post (form name, file name, file type)
+touch('profile.jpg');
 $r->addPostFile('image', 'profile.jpg', 'image/jpeg');
 
 try {
@@ -82,8 +84,8 @@ try {
        $p = new HttpRequestPool;
        // if you want to set _any_ options of the HttpRequest object,
        // you need to do so *prior attaching* to the request pool!
-       $p->attach(new HttpRequest('http://pear.php.net', HTTP_HEAD));
-       $p->attach(new HttpRequest('http://pecl.php.net', HTTP_HEAD));
+       $p->attach(new HttpRequest('http://pear.php.net', HTTP_METH_HEAD));
+       $p->attach(new HttpRequest('http://pecl.php.net', HTTP_METH_HEAD));
 } catch (HttpException $e) {
        print $e;
        exit;
@@ -112,8 +114,8 @@ class Pool extends HttpRequestPool
        public function __construct()
        {
                parent::__construct(
-                       new HttpRequest('http://pear.php.net', HTTP_HEAD),
-                       new HttpRequest('http://pecl.php.net', HTTP_HEAD)
+                       new HttpRequest('http://pear.php.net', HTTP_METH_HEAD),
+                       new HttpRequest('http://pecl.php.net', HTTP_METH_HEAD)
                );
 
                // HttpRequestPool methods socketPerform() and socketSelect() are
@@ -186,7 +188,7 @@ class XmlRpcClient
        public function __construct($url, $namespace = '')
        {
                $this->namespace = $namespace;
-               $this->request = new HttpRequest($url, HTTP_POST);
+               $this->request = new HttpRequest($url, HTTP_METH_POST);
                $this->request->setContentType('text/xml');
        }
 
@@ -205,7 +207,7 @@ class XmlRpcClient
                if ($this->namespace) {
                        $method = $this->namespace .'.'. $method;
                }
-               $this->request->setPostData(xmlrpc_encode_request($method, $params));
+               $this->request->setRawPostData(xmlrpc_encode_request($method, $params));
                $response = $this->request->send();
                if ($response->getResponseCode() != 200) {
                        throw new Exception($response->getBody(), $response->getResponseCode());