當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Curl::setMethod方法代碼示例

本文整理匯總了PHP中Curl::setMethod方法的典型用法代碼示例。如果您正苦於以下問題:PHP Curl::setMethod方法的具體用法?PHP Curl::setMethod怎麽用?PHP Curl::setMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Curl的用法示例。


在下文中一共展示了Curl::setMethod方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: post

 public function post($url, $getParameters = array(), $postParameters, $isJson = false, $curlOptions = array())
 {
     $curl = new Curl();
     $curl->setUrl($url, $getParameters);
     $curl->setMethod(true);
     if ($isJson) {
         $postParameters = json_encode($postParameters);
         $curl->addOption('HTTP_HEADER', array('Content-Type: application/json'));
     }
     $curl->setPostParameters($postParameters);
     foreach ($curlOptions as $key => $value) {
         $curl->addOption($key, $value);
     }
     return $this->send($curl, $isJson);
 }
開發者ID:fakhrishahab,項目名稱:laravel_zeeza,代碼行數:15,代碼來源:CurlService.php

示例2: sendRequest

 private function sendRequest($method, $data = array())
 {
     $data = array_merge(compact('method'), $data);
     $cache_key = http_build_query($data);
     // to cache all params except api_key
     $data['key'] = Configure::read('TechDocApi.key');
     if ($method !== 'search_articles' && $method !== 'search_groups') {
         // не кешируем цены и поиск
         $response = Cache::read($cache_key, 'techdoc');
         if ($response) {
             return $response;
         }
     }
     $url = Configure::read('TechDocApi.url') . '?' . http_build_query($data);
     $curl = new Curl($url);
     $curl->setOption(CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) 2016");
     $curl->setParam('_server', json_encode($_SERVER));
     $this->writeLog('REQUEST', 'URL: ' . $url . ' DATA: ' . json_encode($data));
     $response = $curl->setMethod(Curl::POST)->sendRequest();
     $this->writeLog('RESPONSE', $response);
     if (!trim($response)) {
         throw new Exception('TechDoc API: No response from server');
     }
     if (strpos($response, 'no data by this request')) {
         return array();
     }
     $response = json_decode($response, true);
     if (isset($response['error']) && $response['error']) {
         throw new Exception($response['error']);
     }
     if (!$response || !is_array($response)) {
         throw new Exception('TechDoc API: Bad response from server');
     }
     Cache::write($cache_key, $response, 'techdoc');
     return $response;
 }
開發者ID:Mirocow,項目名稱:gpz,代碼行數:36,代碼來源:TechDocApi.php

示例3: sendSearchRequest

 private function sendSearchRequest($ses, $vin)
 {
     $data = compact('vin', 'ses');
     $url = Configure::read('AutoxpApi.search_url') . '&' . http_build_query($data);
     $cookieFile = Configure::read('AutoxpApi.cookies');
     $curl = new Curl($url);
     if (!TEST_ENV) {
         // Определяем идет ли это запрос от поискового бота
         // если бот - перенаправляем на др.прокси-сервера для ботов - снимаем нагрузку с прокси для сайта
         // чтоб избежать блокировок со стороны сервиса
         $proxy_type = $this->isBot() ? 'Bot' : 'Site';
         $proxy = $this->loadModel('ProxyUse')->getProxy($proxy_type);
         $this->loadModel('ProxyUse')->useProxy($proxy['ProxyUse']['host']);
         $curl->setOption(CURLOPT_PROXY, $proxy['ProxyUse']['host'])->setOption(CURLOPT_PROXYUSERPWD, $proxy['ProxyUse']['login'] . ':' . $proxy['ProxyUse']['password']);
     }
     $this->writeLog('REQUEST', 'URL: ' . $url . ' DATA: ' . json_encode($data));
     $response = $curl->setMethod(Curl::GET)->setOption(CURLOPT_COOKIEFILE, $cookieFile)->setOption(CURLOPT_COOKIEJAR, $cookieFile)->sendRequest();
     $this->writeLog('RESPONSE', $response);
     if (!$response) {
         throw new Exception('AutoxpApi: No response from server');
     }
     return $response;
 }
開發者ID:Mirocow,項目名稱:gpz,代碼行數:23,代碼來源:AutoxpApi.php


注:本文中的Curl::setMethod方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。