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


PHP Request::jsonOpts方法代码示例

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


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

示例1: makeRequest

 /**
  *
  * @param array $param
  *                     data
  *                     url
  *                     method = 'GET'
  *                     headers = []
  * @return array
  */
 public function makeRequest($param)
 {
     //        Yii::info('makeRequest() ' . print_r($param, true));
     $aData = ['response' => null, 'statuscode' => 0];
     if (!isset($param['url'])) {
         return $aData;
     }
     $defaultParam = ['method' => 'GET', 'data' => [], 'headers' => []];
     foreach ($defaultParam as $k => $v) {
         if (!isset($param[$k])) {
             $param[$k] = $v;
         }
     }
     //        $client = new Client(['timeout' => 20]);
     $method = strtolower($param['method']);
     Yii::info('makeRequest(' . $param['method'] . ', ' . $param['url'] . ')' . "\ndata = " . print_r($param['data'], true) . "\nheaders = " . print_r($param['headers'], true));
     try {
         $aDop = [];
         if (count($param['data']) > 0) {
             $sName = 'form_params';
             if ($method != 'post') {
                 $sName = 'query';
             }
             $aDop[$sName] = $param['data'];
         }
         if (count($param['headers']) > 0) {
             $aDop['headers'] = $param['headers'];
         }
         //            Yii::info('makeRequest() aDop = ' . print_r($aDop, true));
         //            $res = $client->request(
         //                $param['method'],
         //                $param['url'],
         //                $aDop
         //            );
         $parsed_url = parse_url($param['url']);
         $parsed_query = [];
         if (isset($parsed_url['query'])) {
             parse_str($parsed_url['query'], $parsed_query);
         }
         if ($method != 'post') {
             $parsed_query = array_merge($parsed_query, isset($aDop['query']) ? $aDop['query'] : []);
             if (isset($aDop['query'])) {
                 unset($aDop['query']);
             }
         }
         $sQuery = http_build_query($parsed_query);
         $url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $parsed_url['path'] . ($sQuery != '' ? '?' . $sQuery : '');
         //            Yii::info('makeRequest() url = ' . print_r($url, true));
         //            Yii::info($method.': '
         //                . $url
         //                . "\n"
         //                . (isset($aDop['headers']) ? (print_r($aDop['headers'], true) . "\n") : '')
         //                . (isset($aDop['form_params']) ? print_r($aDop['form_params'], true) : '')
         //            );
         Request::jsonOpts(true);
         $response = Request::$method($url, isset($aDop['headers']) ? $aDop['headers'] : [], isset($aDop['form_params']) ? $aDop['form_params'] : []);
         $aData = ['response' => $response, 'statuscode' => $response->code];
         if ($response->code >= 500) {
             //                Yii::error('Error makeRequest(): RequestException 500');
             $aData = ['response' => null, 'statuscode' => 500];
         } else {
             if ($response->code >= 400) {
                 //                Yii::error('Error makeRequest(): ClientException ' . print_r($response->body));
                 $aData = ['response' => $response, 'statuscode' => $response->code];
             }
         }
     } catch (\Exception $e) {
         Yii::error('Error makeRequest(): Exception ' . $e->getMessage() . ' ' . $e->getFile() . ' [' . $e->getLine() . '] ');
         $aData = ['response' => null, 'statuscode' => 500];
     }
     Yii::info('makeRequest(): return data = ' . print_r($aData, true));
     return $aData;
 }
开发者ID:mosedu,项目名称:yii2-rapid,代码行数:82,代码来源:Storage.php


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