• php post和get请求


    1. POST请求

    public function post($url, $params = array()) {
            /*初始化*/
            $ch = curl_init();
    
            /*设置变量*/
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
    
            /*执行并获取结果*/
            $result = curl_exec($ch);
         //将result 转成数组
         $result = json_decode($result, true);
    /*释放cURL句柄*/ curl_close($ch); /*返回结果*/ return $result; }

    2. GET请求(解说如上)

    public function get($url) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            $result = curl_exec($ch);
         $result = json_decode($result, true); curl_close(
    $ch); return $result; }
  • 相关阅读:
    kafka副本
    kafka消息丢失
    kafka消费者
    RN8302b调试笔记
    MDK #pragma anon_unions
    [Python笔记]Strip
    [Python笔记]AnyAll
    [Python笔记]元组
    [Python笔记]列表
    嵌入式平台移植Python
  • 原文地址:https://www.cnblogs.com/yyh1/p/6589917.html
Copyright © 2020-2023  润新知