当前位置:网站首页>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)];}
边栏推荐
- AtCoder Beginner Contest 254【VP记录】
- OpenCV经典100题
- DEJA_ Vu3d - cesium feature set 055 - summary description of map service addresses of domestic and foreign manufacturers
- 数据分析思维分析方法和业务知识——分析方法(二)
- Hudi of data Lake (1): introduction to Hudi
- Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4
- 数据分析思维分析方法和业务知识——分析方法(三)
- XML配置文件
- Global and Chinese markets for hinged watertight doors 2022-2028: Research Report on technology, participants, trends, market size and share
- Room cannot create an SQLite connection to verify the queries
猜你喜欢
Idea远程提交spark任务到yarn集群
OS i/o devices and device controllers
Start from the bottom structure and learn the introduction of fpga---fifo IP core and its key parameters
OpenCV经典100题
wx. Getlocation (object object) application method, latest version
Multithreading and high concurrency (8) -- summarize AQS shared lock from countdownlatch (punch in for the third anniversary)
MySQL存储引擎
MySQL storage engine
Arduino六足机器人
Data analysis thinking analysis methods and business knowledge -- analysis methods (II)
随机推荐
Spark SQL UDF function
MySQL存储引擎
OpenCV经典100题
Global and Chinese market of water heater expansion tank 2022-2028: Research Report on technology, participants, trends, market size and share
Extension and application of timestamp
Spark DF增加一列
Yolov5, pychar, Anaconda environment installation
devkit入门
Priority queue (heap)
Determinant learning notes (I)
Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]
如何利用Flutter框架开发运行小程序
STM32 configuration after chip replacement and possible errors
Uniapp development, packaged as H5 and deployed to the server
Location based mobile terminal network video exploration app system documents + foreign language translation and original text + guidance records (8 weeks) + PPT + review + project source code
Knowledge about the memory size occupied by the structure
《强化学习周刊》第52期:Depth-CUPRL、DistSPECTRL & Double Deep Q-Network
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
Key structure of ffmpeg - avformatcontext
Opencv classic 100 questions