/** * 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); }
<?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();
<?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();
<?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();