zoukankan      html  css  js  c++  java
  • 接口数据调用

    php封装GET与POST请求!接口数据调用!

    <?php
    /**
     * Created by PhpStorm.
     * User: rianleycheng
     * Date: 2018-09-10
     * Time: 17:01
     */
    
    namespace AppCommunal;
    
    class Command
    {
        #封装私有get请求
        private function httpGet($url) {
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, 500);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($curl, CURLOPT_URL, $url);
    
            $res = curl_exec($curl);
            curl_close($curl);
    
            return $res;
        }
        #封装私有方法 post
        private function httpPost($url, $param=array()){
            if(!is_array($param)){
                throw new Exception("参数必须为array");
            }
            $httph =curl_init($url);
            curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1);
            curl_setopt($httph,CURLOPT_RETURNTRANSFER,1);
            curl_setopt($httph, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
            curl_setopt($httph, CURLOPT_POST, 1);//设置为POST方式
            curl_setopt($httph, CURLOPT_POSTFIELDS, $param);
            curl_setopt($httph, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($httph, CURLOPT_HEADER,1);
            $rst=curl_exec($httph);
            curl_close($httph);
            return $rst;
        }
    }
    

      

  • 相关阅读:
    获取经纬度 CLLocation
    获取手机 IP
    UIBeaierPath 与 CAShapeLayer
    导航栏转场动画CATransition
    UITextField输入限制/小数/首位等
    程序进入后台继续执行
    发送短信
    网络AFNetworking 3.1
    UIBezierPath
    CoreAnimation 核心动画 / CABasicAnimation/ CAKeyframeAnimation
  • 原文地址:https://www.cnblogs.com/rianley/p/9625659.html
Copyright © 2011-2022 走看看