php
浏览 172 | 评论 6 | 字数 1969
三三酱不蘸酱
2021年02月15日
  • //echo "这是一个测试高亮代码的帖子";
    $data = curl("http://lkaa.top/API/yiyan/api.php","GET",0,0);
    if(!$data){
    exit("获取失败");
    }else{
    exit($data);
    }
    
    //Curl请求,参数:地址,方法,头,参数
    function curl($url, $method, $headers, $params){
        if (is_array($params)) {
            $requestString = http_build_query($params);
        } else {
            $requestString = $params ? : '';
        }
        if (empty($headers)) {
            $headers = array('Content-type: text/json'); 
        } elseif (!is_array($headers)) {
            parse_str($headers,$headers);
        }
        // setting the curl parameters.
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        // turning off the server and peer verification(TrustManager Concept).
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        // setting the POST FIELD to curl
        switch ($method){  
            case "GET" : curl_setopt($ch, CURLOPT_HTTPGET, 1);break;  
            case "POST": curl_setopt($ch, CURLOPT_POST, 1);
                         curl_setopt($ch, CURLOPT_POSTFIELDS, $requestString);break;  
            case "PUT" : curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");   
                         curl_setopt($ch, CURLOPT_POSTFIELDS, $requestString);break;  
            case "DELETE":  curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE");   
                            curl_setopt($ch, CURLOPT_POSTFIELDS, $requestString);break;  
        }
        // getting response from server
        $response = curl_exec($ch);
        
        //close the connection
        curl_close($ch);
        
        //return the response
        if (stristr($response, 'HTTP 404') || $response == '') {
            return array('Error' => '请求错误');
        }
        return $response;
    }
    
    
    

    为什么要用“exit”呢

    大佬说:“exit”输出快

    没错,就是这个理由

    本文作者:三三酱不蘸酱
    本文链接:https://xn--ehqa2882c.cc/index.php/archives/99/
    最后修改时间:2021-02-22 02:28:33
    本站未注明转载的文章均为原创,并采用 CC BY-NC-SA 4.0 授权协议,转载请注明来源,谢谢!
    评论
    与本文无关评论请发留言板。请不要水评论,谢谢。
    textsms
    支持 Markdown 语法
    email
    link
    评论列表
    已有 6 条评论
    2021-02-22 02:27
    表情表情
    2021-02-22 02:27
    2021-02-22 02:25
    .gif
    2021-02-22 02:19
    .gif
    大冰祸
    2021-02-19 01:28
    dalao就是dalao,膜拜
    本站已运行