Esempio n. 1
0
 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();
 }
Esempio n. 2
0
 /**
  * {@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());
 }
Esempio n. 3
0
 public function createTransfer()
 {
     $config = new Config();
     $config->setSSLVerification(false);
     $client = new Client($config);
     // $response = $client->request('http://google.de');
     // echo $response->getHeaders();
     // echo $response->getContent();
     //   curl --request GET \
     // --url  \
     // --header 'accept: application/json' \
     // --header 'authorization: Bearer YOUR ACCESS TOKEN HERE'
     $response = $client->request(['url' => 'https://test-restgw.transferwise.com/v1/me', 'headers' => ['accept' => 'application/json', 'authorization' => 'Bearer 1Y04pF']]);
     echo $response->getHeaders();
     echo $response->getContent();
 }
Esempio n. 4
0
 /**
  * Scraps og:title off the page content
  * @param  string $url
  * @return string
  */
 public function scrap($url)
 {
     $title = 'Unable to parse';
     $this->request->setMethod(HTTP_METH_GET);
     $this->request->setUrl($url);
     try {
         $response = $this->request->send();
         $this->crawler->addHtmlContent($response->getBody());
         $subCrawler = $this->crawler->filterXPath('//head/meta[@property="og:title"]');
         $meta = $subCrawler->getNode(0);
         if ($meta) {
             $title = $meta->getAttribute('content');
         }
     } catch (Exception $e) {
         $title = $e->getMessage();
     }
     return $title;
 }
Esempio n. 5
0
 /**
  * Promise handler
  *
  * @param array|PromiseInterface $promise
  * @param Generator $gen
  */
 private function give($promise, Generator $gen)
 {
     if ($promise instanceof PromiseInterface) {
         $promise->then(function ($result) use($gen) {
             if ($promise = $gen->send($result)) {
                 $this->give($promise, $gen);
             }
         });
     } else {
         all($promise)->then(function ($results) use($gen) {
             if ($promise = $gen->send($results)) {
                 $this->give($promise, $gen);
             }
         });
     }
     $this->client->send();
 }
Esempio n. 6
0
<?php

use http\Client, http\Client\Request;
use http\QueryString;
//$params = new QueryString;
$params["foo"] = "bar";
$params["bar"] = "foo";
$request = new Request("POST", "http://www.google.com");
$request->getBody()->append($params);
$request->setContentType("application/x-www-form-urlencoded");
$client = new Client();
$client->enqueue($request);
$client->send();
$response = $client->getResponse($request);
printf("Sent:\n%s\n\n", $response->getParentMessage());
printf("%s returned '%s'\n%s\n", $response->getTransferInfo("effective_url"), $response->getInfo(), $response->getBody());
?>
 
Sent:
POST http://example.com HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 7
 
bar=foo
 
http://example.com/ returned 'HTTP/1.1 200 OK'
<!doctype html>
<html>
<head>
    <title>Example Domain</title>