当前位置:网站首页>curlpost-php
curlpost-php
2022-07-06 00:36:00 【owenzhang24】
/** * adopt CURL send out HTTP request * * @param string $url // request URL * @param array $postFields // Request parameters * @return mixed * */function curlPost($url, $data = null){// if (is_array($data)) {// $data = http_build_query($data);// } $data = json_encode($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json; charset=utf-8' //json Version needs to be filled in Content-Type: application/json; ) ); curl_setopt($ch, CURLOPT_HEADER, false);// Do not return header information curl_setopt($ch, CURLOPT_POST, 1); if ($data != null) { curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Whether the results are displayed ,1 No display ,0 Show // Determine whether https if (strpos($url, 'https://') !== false) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $UserAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 3.5.21022; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'; curl_setopt($ch, CURLOPT_USERAGENT, $UserAgent); } $data = curl_exec($ch); curl_close($ch); if ($data === FALSE) { $data = ['code' => 400, 'msg' => curl_error($ch)]; } return ['code' => 200, 'data' => json_decode($data, true)];}
边栏推荐
- Power query data format conversion, Split Merge extraction, delete duplicates, delete errors, transpose and reverse, perspective and reverse perspective
- Common API classes and exception systems
- 时间戳的拓展及应用实例
- devkit入门
- Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
- 免费的聊天机器人API
- Go learning --- read INI file
- LeetCode 6005. The minimum operand to make an array an alternating array
- [groovy] JSON string deserialization (use jsonslurper to deserialize JSON strings | construct related classes according to the map set)
- Data analysis thinking analysis methods and business knowledge -- analysis methods (II)
猜你喜欢
数据分析思维分析方法和业务知识——分析方法(二)
剖面测量之提取剖面数据
从底层结构开始学习FPGA----FIFO IP核及其关键参数介绍
Arduino六足机器人
Spark AQE
[groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)
Extension and application of timestamp
Spark SQL null value, Nan judgment and processing
Go learning - dependency injection
Atcoder beginer contest 254 [VP record]
随机推荐
如何制作自己的机器人
XML配置文件
Free chat robot API
LeetCode 6004. Get operands of 0
uniapp开发,打包成H5部署到服务器
Extracting profile data from profile measurement
NLP basic task word segmentation third party Library: ICTCLAS [the third party library with the highest accuracy of Chinese word segmentation] [Chinese Academy of Sciences] [charge]
图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
【DesignMode】组合模式(composite mode)
Go learning - dependency injection
An understanding of & array names
Opencv classic 100 questions
OpenCV经典100题
Leetcode 450 deleting nodes in a binary search tree
Data analysis thinking analysis methods and business knowledge -- analysis methods (II)
Leetcode 44 Wildcard matching (2022.02.13)
OS i/o devices and device controllers
Classical concurrency problem: the dining problem of philosophers
【DesignMode】装饰者模式(Decorator pattern)
Ffmpeg captures RTSP images for image analysis