/** * @param $select * @param $from * @param $where * @param $format */ public function executeQuery($select, $from, $where, $format = 'json') { $yql_query = "select {$select} from {$from} where {$where} "; $this->client->setParameterGet(array('q' => $yql_query, 'format' => $format)); $response = $this->client->send(); /* @var $response \Zend\Http\Response */ if ($response->isSuccess()) { return $response->getBody(); } else { throw new \Exception('Error - Response code: ' . $response->getStatusCode() . ' - query - ' . $yql_query); } }
/** * Verify the user input * * @param $response * * @return Response * @throws \Exception */ public function verify($response) { if (!$this->secretKey) { throw new Exception('Missing secret key'); } $params = array('secret' => $this->secretKey, 'response' => $response); if ($this->ip !== null) { $params['ip'] = $this->ip; } $this->httpClient->setUri(self::VERIFY_SERVER); $this->httpClient->setParameterGet($params); if ($this->options) { $this->httpClient->setOptions($this->options); } $response = $this->httpClient->send(); return new CaptchaResponse($response); }
/** * @param string $method * @param string $url * @param array [optional] $params */ public function request($method, $url, $params = []) { $this->httpClient->setUri($this->moduleOptions->getApiUrl() . '/' . ltrim($url, '/')); $this->httpClient->setMethod($method); if (!is_null($params)) { if ($method == 'post' || $method == 'put') { $this->httpClient->setEncType(HttpClient::ENC_FORMDATA); $this->httpClient->setParameterPost($params); } else { $this->httpClient->setEncType(HttpClient::ENC_URLENCODED); $this->httpClient->setParameterGet($params); } } $response = $this->httpClient->send(); $data = json_decode($response->getBody(), true); return $data; }
/** * Prepare req * * @param Request $request * @return Client * @author Paolo Agostinetto <*****@*****.**> */ protected function prepareHttpRequest(Request $request) { $client = new Client("https://api.thumbalizr.com/", array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE))); $client->setStream(); // Use temp file $client->setParameterGet(array("api_key" => $this->apiKey, "quality" => $request->getQuality(), "width" => $request->getWidth(), "encoding" => $request->getEncoding(), "delay" => $request->getDelay(), "mode" => $request->getMode(), "bwidth" => $request->getBrowserWidth(), "bheight" => $request->getBrowserHeight(), "url" => $request->getUrl() . "&rnd=" . rand(100000, 999999999), "generate" => 0)); return $client; }
/** * @param string|array $identities * * @return bool */ public function delete($identities) { $this->_client->setUri(implode('/', [self::getConfig()['uri'], 'file/delete'])); if (!is_array($identities)) { $identities = (array) $identities; } $this->_client->setParameterGet(['ids' => $identities]); return $this->_client->send()->getStatusCode() == 200; }
public function getGeocodedLatitudeAndLongitude($address) { $client = new Client(); $client->setUri($this->_url); $client->setParameterGet(array('address' => urlencode($address), 'sensor' => 'false')); $client->setMethod('GET'); $result = $client->send(); $response = Decoder::decode($result->getBody(), Json::TYPE_OBJECT); return $response; }
public function cancel($reference) { $url = $this->_server . "/nfe2/cancelar/"; $client = new Client($url); $client->setMethod('GET'); $client->setParameterGet(array('token' => $this->_token, 'ref' => $reference, 'justificativa' => $this->_justification)); $response = $client->send(); $this->_responseBody = $response->getBody(); return $response->isSuccess(); }
public function connect($uri, $post = false, $params = null) { $client = new Client($uri, array('timeout' => 600, 'sslverifypeer' => false)); if (!$post) { $client->setParameterGet($params); } $request = $client->getRequest(); $response = $client->dispatch($request); return $response; }
/** * used by the beo plugin only. We can hardcode the geoCoderUrl for the moment * * @param $input * * @return array|mixed|string */ public function toCoordinates($input) { $client = new Client('http://api.cross-solution.de/geo'); $client->setMethod('GET'); $client->setParameterGet(array('q' => $input, 'country' => 'DE', 'coor' => 1, 'zoom' => 1, 'strict' => 0)); $response = $client->send(); $result = $response->getBody(); $result = json_decode($result); $result = (array) $result->result; return $result; }
private function search($query, $geolocate) { $query = urlencode($query); $client = new Client(); $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl'); $client->setOptions(['timeout' => 60]); $client->setAuth(BING_SEARCH_API_KEY, BING_SEARCH_API_KEY); $client->setUri('https://api.datamarket.azure.com/Bing/Search/v1/Web'); $searchParams = $geolocate ? ['Market' => "'es-Cl'", 'Latitude' => '-33.45', 'Longitude' => '-70.6667', 'Query' => "'{$query}'", '$format' => 'json'] : ['Query' => "'{$query}'", '$format' => 'json']; $client->setParameterGet($searchParams); $response = $client->send(); return $response->isSuccess() ? json_decode($response->getBody()) : null; }
public function getToken() { if ($this->session->fbToken && $this->session->fbTokenExpires) { if (time() <= $this->session->fbTokenExpires) { return $this->session->fbToken; } } $code = $this->getCode(); $this->http->setUri(self::FACEBOOK_AUTH_URI); $this->http->setParameterGet(array('client_id' => $this->fbClientId, 'redirect_uri' => 'http://' . $_SERVER['HTTP_HOST'] . '/', 'client_secret' => $this->fbSecret, 'code' => $code)); $response = $this->http->send(); if ($response->getStatusCode() != \Zend\Http\Response::STATUS_CODE_200) { throw new Exception\AuthException('Bad response from Facebook OAuth'); } parse_str($response->getBody(), $parsedResponse); if (!array_key_exists('access_token', $parsedResponse) || !array_key_exists('expires', $parsedResponse)) { throw new Exception\AuthException('Bad parse from Facebook OAuth'); } $this->session->fbToken = $parsedResponse['access_token']; $this->session->fbTokenExpires = time() + $parsedResponse['expires']; $this->session->offsetUnset('fbCode'); return $this->session->fbToken; }
/** * Requests RAYNET Cloud CRM REST API. Check https://s3-eu-west-1.amazonaws.com/static-raynet/webroot/api-doc.html for any further details. * * @param $serviceName string URL service name * @param $method string Http method * @param $request array request * @return \Zend\Http\Response response */ private function callRaynetcrmRestApi($serviceName, $method, $request) { $client = new Client('', array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false))); $client->setMethod($method); $client->setUri($this->buildUrl($serviceName)); $client->setHeaders(array('X-Instance-Name' => $this->fInstanceName, 'Content-Type' => 'application/json; charset=UTF-8')); $client->setAuth($this->fUserName, $this->fApiKey); if ($method === self::HTTP_METHOD_GET) { $client->setParameterGet($request); } else { $client->setRawBody(Json::encode($request)); } return $client->send(); }
/** * Test that we can properly use Basic HTTP authentication by specifying username and password * in the URI * */ public function testHttpAuthBasicWithCredentialsInUri() { $uri = str_replace('http://', 'http://%s:%s@', $this->baseuri) . 'testHttpAuth.php'; $this->client->setParameterGet(array('user' => 'alice', 'pass' => 'secret', 'method' => 'Basic')); // First - fail password $this->client->setUri(sprintf($uri, 'alice', 'wrong')); $this->client->setMethod('GET'); $res = $this->client->send(); $this->assertEquals(401, $res->getStatusCode(), 'Expected HTTP 401 response was not recieved'); // Now use good password $this->client->setUri(sprintf($uri, 'alice', 'secret')); $this->client->setMethod('GET'); $res = $this->client->send(); $this->assertEquals(200, $res->getStatusCode(), 'Expected HTTP 200 response was not recieved'); }
public function request($service, array $params = [], $method = 'POST') { $result = false; try { $url = sprintf('https://api.superlogica.net/v2/financeiro%s', $service); $client = new Client($url); $client->setAdapter(new Curl()); $client->setMethod($method); $client->setOptions(['curloptions' => [CURLOPT_HEADER => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false]]); $client->setHeaders($this->authHeader); if (!empty($params)) { if ($method == 'GET') { $client->setParameterGet($params); } else { $client->setParameterPost($params); } } $response = $client->send(); if ($response->isSuccess()) { $body = $response->getContent(); $json = Json\Json::decode($body, 1); if (!empty($json[0]['status'])) { if ($json[0]['status'] == '200') { $result = $json; } } else { $result = $json; } } $isException = false; } catch (\Zend\Http\Exception\RuntimeException $e) { $isException = true; } catch (\Zend\Http\Client\Adapter\Exception\RuntimeException $e) { $isException = true; } catch (Json\Exception\RuntimeException $e) { $isException = true; } catch (Json\Exception\RecursionException $e2) { $isException = true; } catch (Json\Exception\InvalidArgumentException $e3) { $isException = true; } catch (Json\Exception\BadMethodCallException $e4) { $isException = true; } if ($isException === true) { //código em caso de problemas no decode } return $result; }
public function sendMsg($cellphones, $msg) { $client = new Client(); $client->setUri($this->smsConfig['uri']); $query = array('CorpID' => $this->smsConfig['corpId'], 'Pwd' => $this->smsConfig['password'], 'Phones' => $cellphones, 'sContent' => iconv('UTF-8', 'GBK', $msg), 'ExtCode' => '', 'SendTime' => ''); $client->setParameterGet($query); $client->setMethod(Request::METHOD_GET); $response = $client->send(); if ($response->isSuccess()) { $result = $response->getBody(); $code = (int) $result; return array('msgCode' => $code, 'msgText' => $this->getMsg($code)); } else { return array('msgCode' => -100, 'msgText' => '短信服务器器响应失败'); } }
/** * Get terms related to the query. * * @return array */ public function getResults() { $this->client->setUri('http://api.dp.la/v2/items'); $this->client->setMethod('GET'); $this->client->setParameterGet($this->getApiInput()); try { $response = $this->client->send(); } catch (TimeoutException $e) { error_log('DPLA API timeout -- skipping recommendations.'); return []; } if (!$response->isSuccess()) { return []; } return $this->processResults($response->getBody()); }
protected function getClient($url, $query, $method = 'POST') { $client = new Client(); $client->setUri($url); if ($method == 'POST') { $client->setMethod(Request::METHOD_POST); if ($query) { $client->setParameterPost($query); } } else { $client->setMethod(Request::METHOD_GET); if ($query) { $client->setParameterGet($query); } } return $client; }
/** * ustawia wspolrzedne geograficzne dla lokalizacji * * @param Entity\Location $location * @return Entity\Location */ public function setCoordinates(Entity\Location $location) { $location->getAddress(); $client = new Http\Client('http://maps.googleapis.com/maps/api/geocode/json'); $client->setParameterGet(array('address' => $location->getAddress())); $client->send(); $response = json_decode($client->getResponse()->getBody()); /** * w wymaganiach nie ma obslugi przypadkow uzycia * - zapisuje lokalizacje pierwszego 'dopasowanego' przez google adresu * */ if ($response->status === 'OK' && !empty($results = $response->results[0])) { $location->setLatitude($results->geometry->location->lat)->setLongitude($results->geometry->location->lng); } return $location; }
/** * @see Athem\Service\Service#call() * @return $this */ public function call() { $request = new Request(); $request->setUri($this->options['url']); $response = new Response(); $client = new Client($this->options['url'], array('useragent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/28.0.1500.71 Chrome/28.0.1500.71 Safari/537.36')); $client->setAdapter(new \Zend\Http\Client\Adapter\Curl()); $client->setParameterGet(array('lang' => $this->options['lang'])); $response = $client->dispatch($request, $response); $this->data = explode("\n", $response->getContent()); foreach ($this->data as $i => $row) { if (!empty($row) && !empty($row[0])) { $this->data[$i] = explode("\t", $row); } else { unset($this->data[$i]); } } array_shift($this->data); return $this; }
/** * @param $userId * @param $accessToken * @param $errorMessage * * @throws Exception\ClientException * * @return bool */ public function validate($userId, $accessToken, &$errorMessage = null) { $client = new Client($this->uri . '/users/self', $this->clientOptions); $client->setMethod('GET'); $client->setParameterGet(['access_token' => $accessToken]); $userData = $this->decodeBody($client->send()); if (isset($userData->error)) { throw new Exception\ClientException($userData->error->message, 400); } if (!isset($userData->id)) { throw new Exception\ClientException('Invalid data returned by provider', 400); } if ($userData->id !== $userId) { $errorMessage = 'user_id mismatch'; return false; } $this->userId = $userData->id; unset($userData->id); $this->userData = (array) $userData; return true; }
/** * Performs HTTP request to given $url using given HTTP $method. * Send additinal query specified by variable/value array, * On success returns HTTP response without headers, false on failure. * * @param string $url OpenID server url * @param string $method HTTP request method 'GET' or 'POST' * @param array $params additional qwery parameters to be passed with * @param int &$staus HTTP status code * request * @return mixed */ protected function _httpRequest($url, $method = 'GET', array $params = array(), &$status = null) { $client = $this->_httpClient; if ($client === null) { $client = new HttpClient($url, array('maxredirects' => 4, 'timeout' => 15, 'useragent' => 'Zend_OpenId')); } else { $client->setUri($url); } $client->resetParameters(); if ($method == Request::METHOD_POST) { $client->setMethod(Request::METHOD_POST); $client->setParameterPost($params); } else { $client->setMethod(Request::METHOD_GET); $client->setParameterGet($params); } try { $response = $client->send(); } catch (\Exception $e) { $this->_setError('HTTP Request failed: ' . $e->getMessage()); return false; } $status = $response->getStatusCode(); $body = $response->getBody(); if ($status == 200 || $status == 400 && !empty($body)) { return $body; } else { $this->_setError('Bad HTTP response'); return false; } }
/** * Initiate an HTTP DELETE request. * As the name implies, it requests that data be delete. * @param array $arr_request_params * @return Ambigous <\FrontCore\Models\ApiRequestModel, \FrontCore\Models\ApiRequestModel> */ public function performDELETERequest($arr_request_params) { if (is_object($arr_request_params) && $arr_request_params instanceof \Zend\Stdlib\ArrayObject) { $arr_request_params = $arr_request_params->getArrayCopy(); } //end if //configure the client $client = new Client(); $client->setMethod("DELETE"); //set GET params if any if (is_array($arr_request_params)) { $client->setParameterGet($arr_request_params); } //end if //execute return self::executeRequest($client); }
/** * Execute request to addthis api * * @param string $metric Metric * @param string $dimension Dimension * @param string $domain Domain * @param string $period Period * @param string $username Usernamer * @param string $password Password * @param string $profile Profile id * * @return mixed */ protected function executeQuery($metric, $dimension, $domain, $period, $username, $password, $profile) { $client = new Client('https://api.addthis.com/analytics/1.0/pub/' . $metric . $dimension . '.json?', array('sslverifypeer' => false, 'timeout' => 2)); $parameters = array('domain' => $domain, 'period' => $period, 'username' => $username, 'password' => $password, 'origin' => 'gotcms_plugin'); if (!empty($profile)) { $parameters['pubid'] = $profile; } $client->setParameterGet($parameters); try { $response = $client->send(); return $response; } catch (\Exception $e) { //Don't care } return false; }
/** * Prepare elements for configuration * * @return void */ public function prepareConfig() { $options = $this->getModel()->getConfig(); $fieldset = new Fieldset('config'); $language = new Element\Select('language'); $language->setLabel('Language')->setLabelAttributes(array('class' => 'col-lg-2 control-label'))->setAttribute('class', 'form-control col-lg-10')->setValueOptions($this->getModel()->getLanguages())->setValue($options['language']); $fieldset->add($language); $ga = new Element\Text('data_ga_property_id'); $ga->setLabel('Google Analytics property ID')->setLabelAttributes(array('class' => 'col-lg-2 control-label'))->setAttribute('class', 'form-control col-lg-10')->setValue($options['data_ga_property_id']); $fieldset->add($ga); $showOnDashboard = new Element\Checkbox('show_stats'); $showOnDashboard->setLabel('Show stats on dashboard')->setLabelAttributes(array('class' => 'col-lg-2 control-label'))->setAttribute('id', 'show_stats')->setAttribute('class', 'input-checkbox')->setValue($options['show_stats']); $fieldset->add($showOnDashboard); $profileId = new Element\Text('profile_id'); $profileId->setLabel('AddThis Profile ID')->setLabelAttributes(array('class' => 'col-lg-2 control-label'))->setAttribute('class', 'form-control col-lg-10')->setValue($options['profile_id']); $fieldset->add($profileId); $username = new Element\Text('username'); $username->setLabel('AddThis Username')->setLabelAttributes(array('class' => 'col-lg-2 control-label'))->setAttribute('class', 'form-control col-lg-10')->setValue($options['username']); $fieldset->add($username); $password = new Element\Password('password'); $password->setLabel('AddThis Password')->setLabelAttributes(array('class' => 'col-lg-2 control-label'))->setAttribute('class', 'form-control col-lg-10')->setValue($options['password']); $fieldset->add($password); $dataTrackClickback = new Element\Checkbox('data_track_clickback'); $dataTrackClickback->setLabel('Track clickback')->setLabelAttributes(array('class' => 'col-lg-2 control-label'))->setAttribute('id', 'data_track_clickback')->setAttribute('class', 'input-checkbox')->setValue($options['data_track_clickback']); $fieldset->add($dataTrackClickback); $dataTrackAddressbar = new Element\Checkbox('data_track_addressbar'); $dataTrackAddressbar->setLabel('Track adressbar')->setLabelAttributes(array('class' => 'col-lg-2 control-label'))->setAttribute('id', 'data_track_addressbar')->setAttribute('class', 'input-checkbox')->setValue($options['data_track_addressbar']); $fieldset->add($dataTrackAddressbar); $jsonConfig = new Element\Textarea('config_json'); $jsonConfig->setLabel('Json config')->setLabelAttributes(array('class' => 'col-lg-2 control-label'))->setAttribute('class', 'form-control col-lg-10')->setValue($options['config_json']); $fieldset->add($jsonConfig); $this->add($fieldset); $this->getInputFilter()->add(array('type' => 'Zend\\InputFilter\\InputFilter', 'language' => array('name' => 'language', 'required' => true), 'data_ga_property_id' => array('name' => 'data_ga_property_id', 'required' => false), 'profile_id' => array('name' => 'profile_id', 'required' => false, 'validators' => array(array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'Can not connect to addthis api'), 'callback' => function ($value, $context = array()) { if (empty($context['username']) or empty($context['password'])) { return false; } return true; })))), 'show_stats' => array('name' => 'show_stats', 'required' => false), 'password' => array('name' => 'password', 'required' => false, 'validators' => array(array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'Can not connect to addthis api'), 'callback' => function ($value, $context = array()) { if (empty($context['username']) or empty($context['profile_id'])) { return false; } return true; })))), 'username' => array('name' => 'username', 'required' => false, 'validators' => array(array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'Can not connect to addthis api'), 'callback' => function ($value, $context = array()) { $client = new Client('https://api.addthis.com/analytics/1.0/pub/shares.json', array('sslverifypeer' => false)); $client->setParameterGet(array('username' => $context['username'], 'password' => $context['password'], 'pubid' => $context['profile_id'])); try { $response = $client->send(); if ($response->isSuccess() == 200) { return true; } } catch (\Exception $e) { //don't care } return false; })))), 'data_track_clickback' => array('name' => 'data_track_clickback', 'required' => false), 'data_track_addressbar' => array('name' => 'data_track_addressbar', 'required' => false), 'json_config' => array('name' => 'json_config', 'required' => false)), 'config'); }
public function getRestResponse($uri, $method = "GET", $params = array()) { $client = new Client(); $client->setAdapter(new Curl()); $client->setUri($uri); $client->setMethod($method); if ($method == "GET") { $client->setParameterGet($params); } else { $client->setParameterPost($params); } $response = $client->send(); return $response; }
/** * Performs an HTTP GET request to the $path. * * @param string $path * @param array $query Array of GET parameters * @throws \Zend\Http\Client\Exception * @return \Zend\Http\Response */ protected function _get($path, array $query = null) { $this->_prepare($path); $this->_localHttpClient->setParameterGet($query); return $this->_localHttpClient->request(Http\Client::GET); }
private function search($query, $geolocate = false, $start = 1) { $query = urlencode($query); $client = new Client(); $client->setOptions(['timeout' => 60]); $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl'); $client->setUri('https://www.googleapis.com/customsearch/v1'); $searchParams = $geolocate ? ['key' => GOOGLE_SEARCH_API_KEY, 'cx' => GOOGLE_SEARCH_CSE_ID, 'q' => $query, 'cr' => 'countryCL', 'gl' => 'cl', 'hl' => 'es', 'googlehost' => 'google.cl', 'start' => $start] : ['key' => GOOGLE_SEARCH_API_KEY, 'cx' => GOOGLE_SEARCH_CSE_ID, 'q' => $query, 'start' => $start]; $client->setParameterGet($searchParams); $response = $client->send(); return $response->isSuccess() ? json_decode($response->getBody()) : null; }
/** * Performs a HTTP request using the specified method * * @param string $method The HTTP method for the request - 'GET', 'POST', * 'PUT', 'DELETE' * @param string $url The URL to which this request is being performed * @param array $headers An associative array of HTTP headers * for this request * @param string $body The body of the HTTP request * @param string $contentType The value for the content type * of the request body * @param int $remainingRedirects Number of redirects to follow if request * s results in one * @return \Zend\Http\Response The response object */ public function performHttpRequest($method, $url, $headers = null, $body = null, $contentType = null, $remainingRedirects = null) { if ($remainingRedirects === null) { $remainingRedirects = self::getMaxRedirects(); } if ($headers === null) { $headers = array(); } // Append a Gdata version header if protocol v2 or higher is in use. // (Protocol v1 does not use this header.) $major = $this->getMajorProtocolVersion(); $minor = $this->getMinorProtocolVersion(); if ($major >= 2) { $headers['GData-Version'] = $major + ($minor === null ? '.' + $minor : ''); } // check the overridden method if (($method == 'POST' || $method == 'PUT') && $body === null && $headers['x-http-method-override'] != 'DELETE') { throw new App\InvalidArgumentException('You must specify the data to post as either a ' . 'string or a child of Zend\\GData\\App\\Entry'); } if ($url === null) { throw new App\InvalidArgumentException('You must specify an URI to which to post.'); } $headers['Content-Type'] = $contentType; if (self::getGzipEnabled()) { // some services require the word 'gzip' to be in the user-agent // header in addition to the accept-encoding header if (strpos($this->_httpClient->getHeader('User-Agent'), 'gzip') === false) { $headers['User-Agent'] = $this->_httpClient->getHeader('User-Agent') . ' (gzip)'; } $headers['Accept-encoding'] = 'gzip, deflate'; } else { $headers['Accept-encoding'] = 'identity'; } // Make sure the HTTP client object is 'clean' before making a request // In addition to standard headers to reset via resetParameters(), // also reset the Slug and If-Match headers $this->_httpClient->resetParameters(); $this->_httpClient->setHeaders(array('Slug', 'If-Match')); // Set the params for the new request to be performed $this->_httpClient->setHeaders($headers); $urlObj = new \Zend\Uri\Url($url); preg_match("/^(.*?)(\\?.*)?\$/", $url, $matches); $this->_httpClient->setUri($matches[1]); $queryArray = $urlObj->getQueryAsArray(); foreach ($queryArray as $name => $value) { $this->_httpClient->setParameterGet($name, $value); } $this->_httpClient->setConfig(array('maxredirects' => 0)); // Set the proper adapter if we are handling a streaming upload $usingMimeStream = false; $oldHttpAdapter = null; if ($body instanceof \Zend\GData\MediaMimeStream) { $usingMimeStream = true; $this->_httpClient->setRawDataStream($body, $contentType); $oldHttpAdapter = $this->_httpClient->getAdapter(); if ($oldHttpAdapter instanceof \Zend\Http\Client\Adapter\Proxy) { $newAdapter = new HttpAdapterStreamingProxy(); } else { $newAdapter = new HttpAdapterStreamingSocket(); } $this->_httpClient->setAdapter($newAdapter); } else { $this->_httpClient->setRawData($body, $contentType); } try { $response = $this->_httpClient->request($method); // reset adapter if ($usingMimeStream) { $this->_httpClient->setAdapter($oldHttpAdapter); } } catch (\Zend\Http\Client\Exception $e) { // reset adapter if ($usingMimeStream) { $this->_httpClient->setAdapter($oldHttpAdapter); } throw new App\HttpException($e->getMessage(), $e); } if ($response->isRedirect() && $response->getStatus() != '304') { if ($remainingRedirects > 0) { $newUrl = $response->getHeader('Location'); $response = $this->performHttpRequest($method, $newUrl, $headers, $body, $contentType, $remainingRedirects); } else { throw new App\HttpException('Number of redirects exceeds maximum', null, $response); } } if (!$response->isSuccessful()) { $exceptionMessage = 'Expected response code 200, got ' . $response->getStatus(); if (self::getVerboseExceptionMessages()) { $exceptionMessage .= "\n" . $response->getBody(); } $exception = new App\HttpException($exceptionMessage); $exception->setResponse($response); throw $exception; } return $response; }
/** * Initiate an HTTP DELETE request. * As the name implies, it requests that data be delete. * @param array $arr_request_params * @return Ambigous <\FrontCore\Models\ApiRequestModel, \FrontCore\Models\ApiRequestModel> */ public function performDELETERequest($arr_request_params) { //configure the client $client = new Client(); $client->setMethod("DELETE"); //set GET params if any if (is_array($arr_request_params)) { $client->setParameterGet($arr_request_params); } //end if //execute return self::executeRequest($client); }