当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::dispatch方法代码示例

本文整理汇总了PHP中Zend\Http\Client::dispatch方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::dispatch方法的具体用法?PHP Client::dispatch怎么用?PHP Client::dispatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Http\Client的用法示例。


在下文中一共展示了Client::dispatch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendRequest

 /**
  * Send request elasticsearch like this :
  * curl -X{$httpMethod} http://host/type/index/{$elasticMethod} -d '{json_decode($content)}'
  * @param int $httpMethod
  * @param string $elasticMethod
  * @param string $content
  *
  * @return Stdlib\ResponseInterface
  */
 public function sendRequest($httpMethod = Request::METHOD_GET, $elasticMethod = null, $content = null)
 {
     $request = new Request();
     $request->setUri($this->url . $elasticMethod)->setMethod($httpMethod)->setContent($content);
     $client = new Client();
     return $client->dispatch($request);
 }
开发者ID:Edencia,项目名称:GeonamesServer,代码行数:16,代码来源:Elasticsearch.php

示例2: PlanJSONManager

 function PlanJSONManager($action, $url, $requestjson, $uid)
 {
     $request = new Request();
     $request->getHeaders()->addHeaders(array('Content-Type' => 'application/json; charset=UTF-8'));
     //$url="";
     try {
         $request->setUri($url);
         $request->setMethod($action);
         $client = new Client();
         if ($action == 'PUT' || $action == 'POST') {
             $client->setUri($url);
             $client->setMethod($action);
             $client->setRawBody($requestjson);
             $client->setEncType('application/json');
             $response = $client->send();
             return $response;
         } else {
             $response = $client->dispatch($request);
             //var_dump(json_decode($response->getBody(),true));
             return $response;
         }
     } catch (\Exception $e) {
         $e->getTrace();
     }
     return null;
 }
开发者ID:shivap87,项目名称:cost,代码行数:26,代码来源:RESTJSONManager.php

示例3: _replace

 protected function _replace($filePath, $photoId, $async = 0)
 {
     $params['async'] = $async;
     $params['photo_id'] = $photoId;
     $finalParams = $this->_httpUtility->assembleParams($this->_endpointReplace, $this->_configOAuth, $params);
     $request = new \Zend\Http\Request();
     $request->setUri($this->_endpointReplace)->setMethod('POST')->setPost(new Parameters($finalParams));
     $this->_httpClient->reset();
     $this->_httpClient->setRequest($request);
     $this->_httpClient->setEncType(\Zend\Http\Client::ENC_FORMDATA, 'ITSCARO');
     $this->_httpClient->setFileUpload($filePath, 'photo');
     $response = $this->_httpClient->dispatch($request);
     $decodedResponse = simplexml_load_string($response->getBody());
     if (!$decodedResponse instanceof \SimpleXMLElement) {
         throw new \Exception('Could not decode response: ' . $response->getBody(), self::ERR_RESPONSE_NOT_XML);
     } else {
         if ($decodedResponse['stat'] == 'ok') {
             if ($async) {
                 return (string) $decodedResponse->ticketid;
             } else {
                 return (string) $decodedResponse->photoid;
             }
         } else {
             throw new \Exception((string) $decodedResponse->err['msg'], (int) $decodedResponse->err['code']);
         }
     }
 }
开发者ID:itscaro,项目名称:zf2-restful,代码行数:27,代码来源:Photo.php

示例4: connect

 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;
 }
开发者ID:ksr10,项目名称:bw,代码行数:10,代码来源:Connect.php

示例5: testPost

 public function testPost()
 {
     $request = new HttpRequest();
     $request->setUri(Form::OGONE_TEST_URL);
     $request->setMethod(HttpRequest::METHOD_POST);
     $request->getPost()->set('PSPID', $this->form->getParam('PSPID'));
     $request->getPost()->set('orderID', $this->form->getParam('orderID'));
     $request->getPost()->set('amount', $this->form->getParam('amount'));
     $request->getPost()->set('currency', $this->form->getParam('currency'));
     $request->getPost()->set('language', $this->form->getParam('language'));
     $request->getPost()->set('CN', $this->form->getParam('CN'));
     $request->getPost()->set('EMAIL', $this->form->getParam('EMAIL'));
     $request->getPost()->set('accepturl', $this->form->getParam('accepturl'));
     $request->getPost()->set('declineurl', $this->form->getParam('declineurl'));
     $request->getPost()->set('exceptionurl', $this->form->getParam('exceptionurl'));
     $request->getPost()->set('cancelurl', $this->form->getParam('cancelurl'));
     $request->getPost()->set('SHASign', $this->form->getSha1Sign());
     $request->getHeaders()->addHeader(\Zend\Http\Header\ContentType::fromString('Content-type: application/x-www-form-urlencoded'));
     $response = $this->httpClient->dispatch($request);
     $this->assertEquals(200, $response->getStatusCode(), 'Ogone response does not have the correct HTTP status code');
     $this->assertSelectCount('form[name="OGONE_CC_FORM"]', 1, $response, 'Ogone response does not include the correct form');
 }
开发者ID:jvandemo,项目名称:ogone,代码行数:22,代码来源:ScenarioTest.php

示例6: send

 public function send($url)
 {
     $request = new Request();
     $request->getHeaders()->addHeaders(array('Content-Type: application/xml; charset=ISO-8859-1'));
     $request->setUri($url);
     $request->setMethod(Request::METHOD_GET);
     // $request->setContent($checkout->parseXML());
     $client = new Client();
     $client->setOptions(array('sslverifypeer' => false));
     $response = $client->dispatch($request);
     if ($response->getBody() == 'Unauthorized') {
         throw new \Exception('Unauthorized access to PagSeguro');
     }
     return simplexml_load_string($response->getBody());
 }
开发者ID:adelarcubs,项目名称:pagseguro_zend,代码行数:15,代码来源:TransactionRequest.php

示例7: call

 public function call($params = null)
 {
     $request = new Request();
     $request->getHeaders()->addHeaders(array('Accept' => 'application/json'));
     if (!is_null($this->bearer_token)) {
         $request->getHeaders()->addHeaders(array('Authorization' => $this->bearer_token));
     }
     $request->setUri($this->endpoint);
     $request->setMethod($this->method);
     if (!is_null($params)) {
         $request->getPost()->fromArray($params);
     }
     $client = new Client($this->endpoint, array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl'));
     $response = $client->dispatch($request);
     return Json::decode($response->getBody(), Json::TYPE_ARRAY);
 }
开发者ID:arnie87,项目名称:gofiliate_test,代码行数:16,代码来源:RestManager.php

示例8: get

 protected function get($url, $data, $options = array())
 {
     $request = new Request();
     $request->setUri($url);
     $request->setMethod('GET');
     $request->getQuery()->fromArray($data);
     $client = new Client();
     $client->setOptions($options);
     $response = $client->dispatch($request);
     try {
         $result = Json::decode($response->getBody(), Json::TYPE_ARRAY);
         return $result;
     } catch (RuntimeException $e) {
         return $response->getBody();
     }
 }
开发者ID:zhangyuxiao,项目名称:qoros,代码行数:16,代码来源:HttpJsonApi.php

示例9: call

 /**
  * @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;
 }
开发者ID:athem,项目名称:athem,代码行数:24,代码来源:Countries.php

示例10: dispatchRequest

 /**
  * @param Request $request
  * @return array
  */
 public function dispatchRequest(Request $request)
 {
     if ($this->profiler) {
         $this->getProfiler()->profilerStart();
     }
     // Send request
     /** @var $response Response */
     $response = $this->httpClient->dispatch($request);
     if ($this->profiler) {
         $this->getProfiler()->profilerFinish($this->httpClient);
     }
     $this->lastRequest = $request;
     $this->lastResponse = $response;
     $validStatusCodes = $this->getValidStatusCodes();
     $responseStatusCode = $response->getStatusCode();
     $decodedResponse = (array) $this->getResponseDecoder()->decode($response);
     if (empty($validStatusCodes) && $response->isSuccess() || in_array($responseStatusCode, $validStatusCodes)) {
         return $decodedResponse;
     }
     throw $this->getInvalidResponseException($decodedResponse, $response);
 }
开发者ID:matryoshka-model,项目名称:service-api,代码行数:25,代码来源:HttpApi.php

示例11: send

 private function send(Checkout $checkout)
 {
     $request = new Request();
     $request->getHeaders()->addHeaders(array('Content-Type: application/xml; charset=ISO-8859-1'));
     $request->setUri($this->options->getWsUrl());
     $request->setMethod(Request::METHOD_POST);
     $request->setContent($checkout->parseXML());
     $client = new Client();
     $response = $client->dispatch($request);
     if ($response->getBody() == 'Unauthorized') {
         throw new \Exception('Unauthorized access to PagSeguro');
     }
     $xml = '';
     try {
         $xml = simplexml_load_string($response->getBody());
     } catch (\Exception $e) {
         throw new \Exception('Error on parse reponse xml. ' . $response->getBody(), 500, $e);
     }
     if ($xml->code) {
         return $xml->code;
     }
     throw new \Exception('An error has occurred: ' . $response->getBody());
 }
开发者ID:adelarcubs,项目名称:pagseguro_zend,代码行数:23,代码来源:PagSeguroRequest.php

示例12: executeRequest

 /**
  * Execute/Dispatch the request.
  * @param Client $client
  * @param Request $request
  * @throws \Exception
  * @return \FrontCore\Models\ApiRequestModel
  */
 private function executeRequest(Client $client, $request = NULL)
 {
     //check if api location isset
     if ($this->api_url == "") {
         throw new \Exception(__CLASS__ . " : Line " . __LINE__ . " : Request could not be performed, API Location is not set", 500);
     }
     //end if
     //should session login information be disabled?
     if ($this->api_session_login === TRUE) {
         //load user session data
         $objUserSession = FrontUserSession::isLoggedIn();
         //check if this is a user or site call
         if ($this->api_pword == "" || !$this->api_pword) {
             //try to extract from session
             if (is_object($objUserSession)) {
                 $this->setAPIUserPword($objUserSession->pword);
             }
             //end if
         }
         //end if
         //set api username
         if ($this->api_user == "" || !$this->api_user) {
             //is api key encoded?
             if (is_object($objUserSession)) {
                 if (isset($objUserSession->api_key_encoded) && $objUserSession->api_key_encoded === TRUE) {
                     $key = $this->getServiceLocator()->get("FrontCore\\Models\\FrontCoreSecurityModel")->decodeValue($objUserSession->uname);
                     $this->setAPIUser($key);
                 } else {
                     //try to extract from session
                     $this->setAPIUser($objUserSession->uname);
                 }
                 //end if
             }
             //end if
         }
         //end if
         //set api key
         if ($this->api_key == "" || !$this->api_key) {
             //is api key encoded?
             if (is_object($objUserSession)) {
                 if (isset($objUserSession->api_key_encoded) && $objUserSession->api_key_encoded === TRUE) {
                     $key = $this->getServiceLocator()->get("FrontCore\\Models\\FrontCoreSecurityModel")->decodeValue($objUserSession->api_key);
                     $this->setAPIKey($key);
                 } else {
                     //try to extract from session
                     $this->setAPIKey($objUserSession->api_key);
                 }
                 //end if
             }
             //end if
         }
         //end if
         require "./config/helpers/ob1.php";
         //@TODO - create own api authentication logic
         // throw new \Exception(__CLASS__ . " : Line " . __LINE__ . ": Implement your api request header logic here", 9999);
     } else {
         if ($this->api_key != "") {
             require "./config/helpers/ob2.php";
             //@TODO - create own api authentication logic
             //throw new \Exception(__CLASS__ . " : Line " . __LINE__ . ": Implement your api request header logic here", 9999);
         } else {
             //bypass to perform info request
             $arr_headers = array();
         }
         //end if
     }
     //end if
     //use manually set headers and then clear them
     if (is_array($this->arr_manual_request_headers)) {
         $arr_headers = $this->arr_manual_request_headers;
         $this->arr_manual_request_headers = FALSE;
     }
     //end if
     try {
         //set user logged in flag for submit to api
         if ($objUserSession) {
             $arr_headers["m3userloggedin"] = time();
         }
         //end if
         //set origin url
         $arr_headers['m3originurl'] = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
         //load event manager
         $event = new EventManager();
         //trigger pre event
         $result = $event->trigger("apiCallExecuted.pre", $this, array("objClient" => $client, "objRequest" => $request, 'url' => self::buildURI()));
         //set timeout
         $client->setOptions(array("timeout" => 60, "sslverifypeer" => FALSE));
         if ($request instanceof Request) {
             $client->setHeaders($arr_headers);
             $response = $client->dispatch($request);
         } else {
             $client->setUri(self::buildURI());
             $client->setHeaders($arr_headers);
//.........这里部分代码省略.........
开发者ID:ettienem3,项目名称:majestic3-open-source,代码行数:101,代码来源:ApiRequestModel.php

示例13: getBOTHSATResult

 function getBOTHSATResult($gpa, $satcrm, $satwrt, $county, $state, $freelunch, $us, $major, $csize, $cpref, $allflag, $schoolname)
 {
     $request = new Request();
     $request->getHeaders()->addHeaders(array('Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'));
     if ($county == null) {
         $county = "";
     }
     if ($major == "-1") {
         $major = null;
     }
     $url = "";
     try {
         $request->setUri(Constants::BOTH_URI_SAT);
         $request->setMethod('GET');
         if ($allflag == "1") {
             $request->setQuery(new Parameters(array('gpa' => $gpa, 'satcrm' => $satcrm, 'satwrt' => $satwrt, 'county' => $county, 'state' => $state, 'size' => $csize, 'style' => $cpref, 'lunch' => $freelunch, 'majors' => $major, "allcolleges" => 'true', 'school' => $schoolname)));
         } else {
             $request->setQuery(new Parameters(array('gpa' => $gpa, 'satcrm' => $satcrm, 'satwrt' => $satwrt, 'county' => $county, 'state' => $state, 'size' => $csize, 'style' => $cpref, 'lunch' => $freelunch, 'majors' => $major, 'school' => $schoolname)));
         }
         $url = Constants::BOTH_URI_SAT . '?' . $request->getQuery()->toString();
         $client = new Client();
         $response = $client->dispatch($request);
         $data = json_decode($response->getBody(), true);
     } catch (\Exception $e) {
         $data['exception'] = "URL not found";
         $data['url'] = $url;
     }
     return $data;
 }
开发者ID:shivap87,项目名称:cost,代码行数:29,代码来源:RESTManager.php

示例14: httpClientAction

 public function httpClientAction()
 {
     # Shows making a HTTP request and seeing response
     $request = new Request();
     $request->setUri('http://example.org');
     $client = new Client();
     #$client->setRequest($request);
     $response = $client->dispatch($request);
     return array('response' => $response);
 }
开发者ID:jingjangjung,项目名称:zf2-example1,代码行数:10,代码来源:AlbumController.php

示例15: getFile

 /**
  * @param array $data
  *
  * @return string
  * @throws Exception\RuntimeException
  */
 private function getFile(array $data)
 {
     $data = array_merge(array('api_token' => $this->options->getApiToken(), 'id' => $this->options->getProjectId(), 'action' => 'export'), $data);
     $fileKey = md5(json_encode($data));
     if (isset($this->files[$fileKey])) {
         return $this->files[$fileKey];
     }
     $client = new Http\Client(null, $this->options->getClient());
     $request = new Http\Request();
     $request->setUri($this->options->getUrl());
     $request->setMethod(Http\Request::METHOD_POST);
     $request->setContent(http_build_query($data));
     usleep($this->options->getRequestDelay());
     /** @var \Zend\Http\Response $response */
     $response = $client->dispatch($request);
     if (!$response->isSuccess()) {
         throw new Exception\RuntimeException('Request was not successful');
     }
     /** @var \stdClass $content */
     $content = json_decode($response->getContent());
     if ($content->response->code != 200) {
         throw new Exception\RuntimeException($content->response->message);
     }
     $this->files[$fileKey] = $content->item;
     return $this->files[$fileKey];
 }
开发者ID:maikay,项目名称:zf2-poeditor-php-client,代码行数:32,代码来源:ClientService.php


注:本文中的Zend\Http\Client::dispatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。