コード例 #1
0
 public function updateBanner()
 {
     $url = (new Owl())->getUrl('', 'banners');
     $request = new Request($url);
     $request->getOptions()->set(CURLOPT_TIMEOUT, 8)->set(CURLOPT_RETURNTRANSFER, true)->set(CURLOPT_USERAGENT, $this->di->get('config')->curlUserAgent);
     $response = $request->send();
     $httpCode = $response->getInfo(CURLINFO_HTTP_CODE);
     if ($response->hasError() || $httpCode != 200) {
         $error = $response->getError()->getMessage();
         throw new \Exception("Ошибка!!! http code: {$httpCode} message: {$error} url: {$url}");
     }
     $content = json_decode($response->getContent(), true);
     parent::createBanner($content);
 }
コード例 #2
0
 /**
  * Test synchronous request through send()
  * 
  * @return void
  */
 public function testRequestSynchronous()
 {
     /**
      * Successful request
      */
     $req = new cURL\Request();
     $req->getOptions()->set(CURLOPT_URL, $this->okTestUrl)->set(CURLOPT_RETURNTRANSFER, true);
     $this->assertInternalType('resource', $req->getHandle());
     $this->validateSuccesfulResponse('/', $req->send());
     /**
      * Error request
      */
     $req = new cURL\Request();
     $req->getOptions()->set(CURLOPT_URL, $this->errorTestUrl)->set(CURLOPT_TIMEOUT, 1)->set(CURLOPT_RETURNTRANSFER, true);
     $this->validateTimeoutedResponse($req->send());
 }
コード例 #3
0
ファイル: Owl.php プロジェクト: argentum88/owl-client
 public function request($url, $useOwlServer = true)
 {
     $url = urldecode($url);
     PH_DEBUG ? Debugger::dumpBar($url, 'url') : null;
     if ($useOwlServer) {
         $url = $this->getUrl($url);
         $request = new Request($url);
         $request->getOptions()->set(CURLOPT_TIMEOUT, 8)->set(CURLOPT_RETURNTRANSFER, true)->set(CURLOPT_USERAGENT, $this->di->get('config')->curlUserAgent);
         $response = $request->send();
         $content = json_decode($response->getContent(), true);
         $url = $this->getUrl('', 'common');
         $request = new Request($url);
         $request->getOptions()->set(CURLOPT_TIMEOUT, 8)->set(CURLOPT_RETURNTRANSFER, true)->set(CURLOPT_USERAGENT, $this->di->get('config')->curlUserAgent);
         $response = $request->send();
         $common = json_decode($response->getContent(), true);
         return $content + $common;
     }
     $response = Contents::get($url);
     return $response;
 }
コード例 #4
0
ファイル: RequestTest.php プロジェクト: im286er/curl-easy
 /**
  * Tests whether 'complete' event on individual Request has not been fired
  * when Request::send() was used.
  */
 public function testRequestCompleteEventSynchronous()
 {
     $eventFired = 0;
     $req = new cURL\Request();
     $req->getOptions()->set(CURLOPT_URL, $this->createRequestUrl())->set(CURLOPT_RETURNTRANSFER, true);
     $req->addListener('complete', function (cURL\Event $event) use(&$eventFired) {
         $eventFired++;
     });
     $req->send();
     $this->assertEquals(0, $eventFired);
 }
コード例 #5
0
 /**
  * Execute the request.
  * @throws CurlException
  * @throws \Quazardous\PriceministerWs\RuntimeException
  * @throws ApiException
  * @return \Quazardous\PriceministerWs\Response\BasicResponse
  */
 public function execute()
 {
     $url = $this->getOption('url') . '?' . http_build_query($this->getParameters());
     $curl = new CurlRequest($url);
     $curl->getOptions()->set(CURLOPT_TIMEOUT, $this->getOption('timeout'))->set(CURLOPT_RETURNTRANSFER, true)->set(CURLOPT_HEADER, true);
     $curlResponse = $curl->send();
     if ($curlResponse->hasError()) {
         $error = $curlResponse->getError();
         throw new CurlException($error ? $error->getMessage() : 'Unkown exception', $error ? $error->getCode() : null);
     }
     $code = $curlResponse->getInfo(CURLINFO_HTTP_CODE);
     $content = $curlResponse->getContent();
     $header_size = $curlResponse->getInfo(CURLINFO_HEADER_SIZE);
     $header = substr($content, 0, $header_size);
     $body = substr($content, $header_size);
     $basic = new BasicResponse($header, $body);
     $start = substr($body, 0, 256);
     $matches = null;
     if (preg_match('@<\\?xml[^>]+encoding="[^\\s"]+[^?]*\\?>\\s*<errorresponse@si', $start, $matches)) {
         $xml = simplexml_load_string($body);
         if ($xml === false) {
             throw new RuntimeException('Response content is no valid XML', RuntimeException::NO_VALID_XML);
         }
         $details = array();
         if ($xml->error->details->detail) {
             foreach ($xml->error->details->detail as $detail) {
                 $details[] = (string) $detail;
             }
         }
         throw new ApiException($xml->error->message, $xml->error->type, $xml->error->code, $details, $basic);
     }
     if ($code != 200) {
         $e = new RuntimeException('HTTP code is not 200 (' . $code . ')', RuntimeException::HTTP_CODE_NOT_200);
         $e->setResponse($basic);
         throw $e;
     }
     return $basic;
 }