Esempio n. 1
0
 /**
  * Send this HTTP request
  *
  * @throws Horde_Http_Exception
  * @return Horde_Http_Response_Base
  */
 public function send()
 {
     // at this time only the curl driver is supported
     $client = new \http\Client('curl');
     $body = new \http\Message\Body();
     $data = $this->data;
     if (is_array($data)) {
         $body->addForm($data);
     } else {
         $body->append($data);
     }
     $httpRequest = new \http\Client\Request($this->method, (string) $this->uri, $this->headers, $body);
     $client->setOptions($this->_httpOptions());
     $client->enqueue($httpRequest);
     try {
         $client->send();
         $httpResponse = $client->getResponse($httpRequest);
     } catch (\http\Exception $e) {
         throw new Horde_Http_Exception($e);
     }
     return new Horde_Http_Response_Peclhttp2((string) $this->uri, $httpResponse);
 }
Esempio n. 2
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append('{"number":1,"string":"f\\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}');
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders(array('content-type' => 'application/json'));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Esempio n. 3
0
 /**
  * Processes a PUT request.
  *
  * @param string $path File path
  * @param string $data Data
  * @param boolean $isFile Determines if $data is a file name or actual data
  * @throws \Jyxo\Webdav\DirectoryNotCreatedException If the target directory cannot be created
  * @throws \Jyxo\Webdav\FileNotCreatedException If the file cannot be created
  * @throws \Jyxo\Webdav\Exception On error
  */
 protected function processPut($path, $data, $isFile)
 {
     $requests = $this->createAllRequests($path, self::METHOD_PUT);
     foreach ($requests as $request) {
         if ($isFile) {
             $body = new \http\Message\Body(fopen($data, 'r'));
             $request->setBody($body);
         } else {
             $body = new \http\Message\Body();
             $body->append($data);
             $request->setBody($body);
         }
     }
     $success = true;
     foreach ($this->sendAllRequests($requests) as $response) {
         switch ($response->getResponseCode()) {
             // Saved
             case self::STATUS_200_OK:
             case self::STATUS_201_CREATED:
                 break;
                 // An existing file was modified
             // An existing file was modified
             case self::STATUS_204_NO_CONTENT:
                 break;
                 // The directory might not exist
             // The directory might not exist
             case self::STATUS_403_FORBIDDEN:
             case self::STATUS_404_NOT_FOUND:
             case self::STATUS_409_CONFLICT:
                 $success = false;
                 break;
                 // Could not save
             // Could not save
             default:
                 throw new \Jyxo\Webdav\FileNotCreatedException(sprintf('File %s cannot be created.', $path));
         }
     }
     // Saved
     if ($success) {
         return;
     }
     // Not saved, try creating the directory first
     if ($this->createDirectoriesAutomatically) {
         try {
             $this->mkdir(dirname($path));
         } catch (DirectoryNotCreatedException $e) {
             throw new \Jyxo\Webdav\FileNotCreatedException(sprintf('File %s cannot be created.', $path), 0, $e);
         }
     }
     // Try again
     foreach ($this->sendAllRequests($requests) as $response) {
         // 201 means saved
         if (self::STATUS_201_CREATED !== $response->getResponseCode()) {
             throw new \Jyxo\Webdav\FileNotCreatedException(sprintf('File %s cannot be created.', $path));
         }
     }
 }
Esempio n. 4
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->addForm(NULL, array(array('name' => 'foo', 'type' => 'text/plain', 'file' => 'hello.txt', 'data' => 'Hello World')));
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
$request->setBody($body);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Esempio n. 5
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append('Hello World');
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders(array('content-type' => 'text/plain'));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Esempio n. 6
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(new http\QueryString(array('foo' => 'bar')));
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setQuery(new http\QueryString(array('foo' => array('bar', 'baz'), 'baz' => 'abc', 'key' => 'value')));
$request->setHeaders(array('content-type' => 'application/x-www-form-urlencoded', 'accept' => 'application/json'));
$client->setCookies(array('bar' => 'baz', 'foo' => 'bar'));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Esempio n. 7
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->addForm(NULL, array(array('name' => 'foo', 'type' => 'text/plain', 'file' => 'test/fixtures/files/hello.txt', 'data' => null)));
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
$request->setBody($body);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Esempio n. 8
0
<?php

$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->addForm(array('foo' => 'bar'), NULL);
$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
$request->setBody($body);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();