当前位置:网站首页>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)];}
边栏推荐
- 孤勇者
- NLP generation model 2017: Why are those in transformer
- MySQL storage engine
- [designmode] Decorator Pattern
- Atcoder beginer contest 254 [VP record]
- Uniapp development, packaged as H5 and deployed to the server
- Global and Chinese market of water heater expansion tank 2022-2028: Research Report on technology, participants, trends, market size and share
- Go learning --- read INI file
- Data analysis thinking analysis methods and business knowledge - analysis methods (III)
- 关于slmgr命令的那些事
猜你喜欢
[groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)
Model analysis of establishment time and holding time
Browser reflow and redraw
Spark SQL空值Null,NaN判断和处理
OpenCV经典100题
Hudi of data Lake (2): Hudi compilation
Problems and solutions of converting date into specified string in date class
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
随机推荐
Data analysis thinking analysis methods and business knowledge -- analysis methods (II)
如何制作自己的机器人
Idea remotely submits spark tasks to the yarn cluster
Analysis of the combination of small program technology advantages and industrial Internet
How to solve the problems caused by the import process of ecology9.0
Spark AQE
Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)
【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
Room cannot create an SQLite connection to verify the queries
SQLServer连接数据库读取中文乱码问题解决
2022.7.5-----leetcode. seven hundred and twenty-nine
常用API类及异常体系
Global and Chinese markets of universal milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode 6004. Get operands of 0
Notepad + + regular expression replace String
Room cannot create an SQLite connection to verify the queries
NLP text processing: lemma [English] [put the deformation of various types of words into one form] [wet- > go; are- > be]
Problems and solutions of converting date into specified string in date class
Classical concurrency problem: the dining problem of philosophers
XML Configuration File