当前位置:网站首页>curlpost-php
curlpost-php
2022-07-06 00:36: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)];}
边栏推荐
- LeetCode 6006. Take out the least number of magic beans
- Folding and sinking sand -- weekly record of ETF
- Go learning - dependency injection
- PHP determines whether an array contains the value of another array
- Leetcode 44 Wildcard matching (2022.02.13)
- 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]
- Global and Chinese market of water heater expansion tank 2022-2028: Research Report on technology, participants, trends, market size and share
- 【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
- Spark AQE
- 常用API类及异常体系
猜你喜欢
Spark AQE
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
MySQL storage engine
2022-02-13 work record -- PHP parsing rich text
Folding and sinking sand -- weekly record of ETF
Knowledge about the memory size occupied by the structure
Multithreading and high concurrency (8) -- summarize AQS shared lock from countdownlatch (punch in for the third anniversary)
Determinant learning notes (I)
从 1.5 开始搭建一个微服务框架——调用链追踪 traceId
【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
随机推荐
[designmode] Decorator Pattern
LeetCode 8. String conversion integer (ATOI)
JS can really prohibit constant modification this time!
Common API classes and exception systems
Spark AQE
Uniapp development, packaged as H5 and deployed to the server
Search (DFS and BFS)
Gd32f4xx UIP protocol stack migration record
Spark SQL null value, Nan judgment and processing
Mysql - CRUD
从底层结构开始学习FPGA----FIFO IP核及其关键参数介绍
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
Atcoder beginer contest 258 [competition record]
Key structure of ffmpeg -- AVCodecContext
MIT博士论文 | 使用神经符号学习的鲁棒可靠智能系统
【DesignMode】适配器模式(adapter pattern)
Determinant learning notes (I)
Yolov5, pychar, Anaconda environment installation
OS i/o devices and device controllers
LeetCode 1598. Folder operation log collector