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