Exemplo n.º 1
0
 /**
  * Execute SOAP request using CURL
  *
  * @param string $request
  * @param string $location
  * @param string $action
  * @param int $version
  * @param int $one_way
  * @return string
  * @throws \Exception
  */
 public function __doRequest($request, $location, $action, $version, $one_way = 0)
 {
     $this->curlPlusClient->initialize($location, true);
     $this->curlPlusClient->setCurlOpt(CURLOPT_POSTFIELDS, (string) $request);
     $this->curlPlusClient->setCurlOpts($this->curlOptArray);
     // Add the header strings
     foreach ($this->requestHeaders as $k => $v) {
         $this->getCurlClient()->setRequestHeader($k, $v);
     }
     $this->curlPlusClient->setRequestHeader('SOAPAction', $action);
     $ret = $this->curlPlusClient->execute();
     if ($this->debugEnabled()) {
         $this->_debugQueries[] = array('headers' => $ret->getRequestHeaderArray(), 'body' => (string) $request);
         $this->_debugResults[] = $ret;
     }
     if ($ret->responseBody == false || $ret->httpCode !== 200) {
         throw new \Exception('DCarbone\\SoapClientPlus::__doRequest - CURL Error during call: "' . addslashes($ret->curlError) . '", "' . addslashes($ret->responseBody) . '"');
     }
     return $ret->responseBody;
 }
Exemplo n.º 2
0
 /**
  * Execute SOAP request using CURL
  *
  * @param string $request
  * @param string $location
  * @param string $action
  * @param int $version
  * @param int $one_way
  * @return string
  * @throws \Exception
  */
 public function __doRequest($request, $location, $action, $version, $one_way = 0)
 {
     $this->curlPlusClient->initialize($location, true);
     $this->curlPlusClient->setCurlOpt(CURLOPT_POSTFIELDS, (string) $request);
     $this->curlPlusClient->setCurlOpts($this->curlOptArray);
     // Add the header strings
     foreach ($this->defaultRequestHeaders as $headerString) {
         $this->getClient()->addRequestHeaderString($headerString);
     }
     $this->curlPlusClient->addRequestHeaderString('SOAPAction: "' . $action . '"');
     $ret = $this->curlPlusClient->execute();
     if ($this->isDebug()) {
         $this->debugQueries[] = array('headers' => $ret->getRequestHeaders(), 'body' => (string) $request);
         $this->debugResults[] = array('code' => $ret->getHttpCode(), 'headers' => $ret->getResponseHeaders(), 'response' => (string) $ret->getResponse());
     }
     if ($ret->getResponse() == false || $ret->getHttpCode() != 200) {
         throw new \Exception('DCarbone\\SoapClientPlus::__doRequest - CURL Error during call: "' . addslashes($ret->getError()) . '", "' . addslashes($ret->getResponse()) . '"');
     }
     return $ret->getResponse();
 }
Exemplo n.º 3
0
 /**
  * @param string $content
  * @param array $parameters
  * @param bool $outputToFile
  * @param string $filename
  * @param bool $includeHeadersInResponse
  * @param bool $removeFileOnShutdown
  * @return \DCarbone\CurlPlus\Response\CurlPlusResponseInterface
  * @internal param $type
  */
 private function _executeRequest($content, array $parameters, $outputToFile = true, $filename = null, $includeHeadersInResponse = false, $removeFileOnShutdown = true)
 {
     $postFieldString = $this->_buildPostFields($content, $parameters);
     $this->_curlClient->initialize($this->_redcapApiEndpoint, false);
     $this->_curlClient->setCurlOpt(CURLOPT_POST, true)->setCurlOpt(CURLOPT_FOLLOWLOCATION, true)->setCurlOpt(CURLOPT_POSTFIELDS, $postFieldString)->removeCurlOpt(CURLOPT_FILE);
     if ($includeHeadersInResponse) {
         $this->_curlClient->setCurlOpt(CURLOPT_HEADER, true);
     } else {
         $this->_curlClient->setCurlOpt(CURLOPT_HEADER, false);
     }
     if ($outputToFile) {
         if (null === $filename) {
             $filename = sprintf('%s/%s.xml', $this->_tempDirectory, sha1($postFieldString));
         }
         $fh = fopen($filename, 'w+b');
         if ($fh) {
             $this->_curlClient->setCurlOpt(CURLOPT_RETURNTRANSFER, false)->setCurlOpt(CURLOPT_FILE, $fh);
             $response = $this->_curlClient->execute(false);
             if (($error = $response->getError()) === '' && $response->getHttpCode() === 200) {
                 if ($removeFileOnShutdown) {
                     $this->_files[] = $filename;
                 }
                 fclose($fh);
                 return $response;
             }
             throw new \RuntimeException(sprintf('Error received when querying for "%s" content. Code: %s,  Error: "%s"', $content, $response->getHttpCode(), $error));
         }
         throw new \RuntimeException(sprintf('Unable to open temp file "%s" for writing. Please check runtime permissions at location.', $filename));
     } else {
         $this->_curlClient->setCurlOpt(CURLOPT_RETURNTRANSFER, true);
         $response = $this->_curlClient->execute(false);
         if (($error = $response->getError()) === '' && $response->getHttpCode() === 200) {
             return $response;
         }
         throw new \RuntimeException(sprintf('Error received when querying for "%s" content. HTTP Code: %s, Error: "%s"', $content, $response->getHttpCode(), $error));
     }
 }
Exemplo n.º 4
0
 /**
  * @param string $url
  * @param string $method
  * @param array $userOpts
  * @param array $defaultOpts
  * @param array $userHeaders
  * @param array $defaultHeaders
  * @param string|array|object $requestBody
  * @return CurlPlusResponse
  */
 private static function _execute($url, $method, array $userOpts, array $defaultOpts, array $userHeaders, array $defaultHeaders = array(), $requestBody = null)
 {
     self::$_client->initialize($url);
     switch ($method) {
         case 'GET':
             $defaultOpts[CURLOPT_HTTPGET] = true;
             break;
         case 'POST':
             $defaultOpts[CURLOPT_POST] = true;
             break;
         default:
             $defaultOpts[CURLOPT_CUSTOMREQUEST] = $method;
     }
     $bodyType = gettype($requestBody);
     if (null !== $requestBody && in_array($method, self::$_methodsWithBody) && !isset($userOpts[CURLOPT_POSTFIELDS])) {
         if ('array' === $bodyType || 'object' === $bodyType) {
             $requestBody = http_build_query($requestBody);
         }
         $defaultOpts[CURLOPT_POSTFIELDS] = $requestBody;
     }
     self::$_client->setCurlOpts($userOpts + $defaultOpts);
     self::$_client->setRequestHeaders($userHeaders + $defaultHeaders);
     return self::$_client->execute(true);
 }
Exemplo n.º 5
0
 /**
  * @covers \DCarbone\CurlPlus\CurlPlusClient::execute
  * @depends testCanConstructWithNoArguments
  * @expectedException \RuntimeException
  * @param \DCarbone\CurlPlus\CurlPlusClient $curlClient
  */
 public function testExceptionThrownWhenTryingToExecuteRequestWithEmptyConstructorArguments(\DCarbone\CurlPlus\CurlPlusClient $curlClient)
 {
     $curlClient->execute();
 }