public function send()
 {
     if (is_null($this->getBody())) {
         $body = null;
     } else {
         $body = new Body();
         $body->append($this->getBody());
     }
     $request = new Request($this->getMethod(), 'https://' . $this->getUrl(), $this->getHeaders(), $body);
     $request->addQuery($this->getQuery());
     $client = new Client();
     $client->enqueue($request)->send();
     $this->response = $client->getResponse();
 }
 /**
  * {@inheritdoc}
  */
 protected function sendInternalRequest(InternalRequestInterface $internalRequest)
 {
     $body = new Body();
     $body->append($this->prepareBody($internalRequest));
     $request = new Request($internalRequest->getMethod(), $uri = (string) $internalRequest->getUri(), $this->prepareHeaders($internalRequest), $body);
     $httpVersion = $internalRequest->getProtocolVersion() === InternalRequestInterface::PROTOCOL_VERSION_1_0 ? \http\Client\Curl\HTTP_VERSION_1_0 : \http\Client\Curl\HTTP_VERSION_1_1;
     $request->setOptions(array('protocol' => $httpVersion, 'timeout' => $this->getConfiguration()->getTimeout()));
     try {
         $this->client->reset()->enqueue($request)->send();
     } catch (\Exception $e) {
         throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
     }
     $response = $this->client->getResponse();
     return $this->getConfiguration()->getMessageFactory()->createResponse($response->getResponseCode(), $response->getHttpVersion(), $response->getHeaders(), $response->getBody()->getResource());
 }
Example #3
0
 public function testToArrayWithoutDefaults()
 {
     $body = new Body();
     $body->append(rand(0, 100000));
     $response = new Response();
     $response->setBody($body);
     $array = $response->toArray(false);
     $this->assertSame(0, $array['responseCode']);
     $this->assertSame((string) $body, $array['body']);
     $this->assertFalse(isset($array['headers']['Server']));
     $this->assertFalse(isset($array['headers']['Content-Type']));
     $this->assertSame((string) strlen($body), $array['headers']['Content-Length']);
 }
Example #4
0
 /**
  * Sets POST fields
  *
  * @param array $fields
  */
 public function setPostFields(array $fields)
 {
     $this->post = $fields;
     $body = new Message\Body();
     $body->append(http_build_query($fields));
     parent::setBody($body);
     $_POST = $fields;
     $_REQUEST = array_merge($_GET, $_POST);
 }