当前位置:网站首页>curlpost-php
curlpost-php
2022-07-06 00:33:00 【owenzhang24】
/** * 通过CURL发送HTTP请求 * * @param string $url //请求URL * @param array $postFields //请求参数 * @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版本需要填写 Content-Type: application/json; ) ); curl_setopt($ch, CURLOPT_HEADER, false);//不返回头部信息 curl_setopt($ch, CURLOPT_POST, 1); if ($data != null) { curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //结果是否显示出来,1不显示,0显示 //判断是否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)];}
边栏推荐
- 孤勇者
- Common API classes and exception systems
- Spark DF增加一列
- [designmode] adapter pattern
- MySql——CRUD
- 剖面测量之提取剖面数据
- 常用API类及异常体系
- OpenCV经典100题
- Anconda download + add Tsinghua +tensorflow installation +no module named 'tensorflow' +kernelrestart: restart failed, kernel restart failed
- N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2
猜你喜欢
Classic CTF topic about FTP protocol
How to solve the problems caused by the import process of ecology9.0
《强化学习周刊》第52期:Depth-CUPRL、DistSPECTRL & Double Deep Q-Network
看抖音直播Beyond演唱会有感
Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
常用API类及异常体系
Hudi of data Lake (2): Hudi compilation
The relationship between FPGA internal hardware structure and code
notepad++正則錶達式替換字符串
Problems and solutions of converting date into specified string in date class
随机推荐
Determinant learning notes (I)
如何利用Flutter框架开发运行小程序
电机的简介
《强化学习周刊》第52期:Depth-CUPRL、DistSPECTRL & Double Deep Q-Network
Global and Chinese markets for hinged watertight doors 2022-2028: Research Report on technology, participants, trends, market size and share
SQLServer连接数据库读取中文乱码问题解决
Global and Chinese market of valve institutions 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode 6006. Take out the least number of magic beans
Atcoder beginer contest 254 [VP record]
The relationship between FPGA internal hardware structure and code
Hudi of data Lake (2): Hudi compilation
LeetCode 1598. Folder operation log collector
FFmpeg学习——核心模块
How to use the flutter framework to develop and run small programs
建立时间和保持时间的模型分析
wx. Getlocation (object object) application method, latest version
Uniapp development, packaged as H5 and deployed to the server
【DesignMode】组合模式(composite mode)
Spark SQL UDF function
Opencv classic 100 questions