当前位置: 首页>>代码示例>>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;未经允许,请勿转载。