当前位置:网站首页>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)];}
边栏推荐
- [Chongqing Guangdong education] reference materials for Zhengzhou Vocational College of finance, taxation and finance to play around the E-era
- [designmode] adapter pattern
- 常用API类及异常体系
- LeetCode 6006. Take out the least number of magic beans
- 云导DNS和知识科普以及课堂笔记
- Hudi of data Lake (1): introduction to Hudi
- Leetcode 44 Wildcard matching (2022.02.13)
- CTF daily question day44 rot
- synchronized 和 ReentrantLock
- 小程序容器可以发挥的价值
猜你喜欢
建立时间和保持时间的模型分析
OS i/o devices and device controllers
看抖音直播Beyond演唱会有感
Model analysis of establishment time and holding time
Classical concurrency problem: the dining problem of philosophers
notepad++正則錶達式替換字符串
KDD 2022 | 脑电AI助力癫痫疾病诊断
LeetCode 1598. Folder operation log collector
Atcoder beginer contest 258 [competition record]
Room cannot create an SQLite connection to verify the queries
随机推荐
Pointer pointer array, array pointer
Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
MDK debug时设置数据实时更新
STM32按键消抖——入门状态机思维
[groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)
Browser reflow and redraw
[designmode] Decorator Pattern
免费的聊天机器人API
详细页返回列表保留原来滚动条所在位置
Opencv classic 100 questions
Spark SQL空值Null,NaN判断和处理
Browser local storage
Extension and application of timestamp
STM32 key chattering elimination - entry state machine thinking
LeetCode 6005. The minimum operand to make an array an alternating array
Knowledge about the memory size occupied by the structure
[QT] QT uses qjson to generate JSON files and save them
Uniapp development, packaged as H5 and deployed to the server
【线上小工具】开发过程中会用到的线上小工具合集
Codeforces gr19 D (think more about why the first-hand value range is 100, JLS yyds)