当前位置:网站首页>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)];}
边栏推荐
- Codeforces round 804 (Div. 2) [competition record]
- 小程序容器可以发挥的价值
- Leetcode 44 Wildcard matching (2022.02.13)
- Idea remotely submits spark tasks to the yarn cluster
- Extracting profile data from profile measurement
- STM32 key chattering elimination - entry state machine thinking
- FFT learning notes (I think it is detailed)
- How to make your own robot
- wx. Getlocation (object object) application method, latest version
- Folding and sinking sand -- weekly record of ETF
猜你喜欢
FFT learning notes (I think it is detailed)
MYSQL GROUP_ The concat function realizes the content merging of the same ID
The relationship between FPGA internal hardware structure and code
Introduction of motor
如何解决ecology9.0执行导入流程流程产生的问题
notepad++正則錶達式替換字符串
Spark AQE
MySQL functions
Common API classes and exception systems
Anconda download + add Tsinghua +tensorflow installation +no module named 'tensorflow' +kernelrestart: restart failed, kernel restart failed
随机推荐
云导DNS和知识科普以及课堂笔记
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
如何解决ecology9.0执行导入流程流程产生的问题
剖面测量之提取剖面数据
FPGA内部硬件结构与代码的关系
Global and Chinese market of valve institutions 2022-2028: Research Report on technology, participants, trends, market size and share
Hudi of data Lake (2): Hudi compilation
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
Free chat robot API
Global and Chinese markets for pressure and temperature sensors 2022-2028: Research Report on technology, participants, trends, market size and share
图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
Room cannot create an SQLite connection to verify the queries
详细页返回列表保留原来滚动条所在位置
The relationship between FPGA internal hardware structure and code
Spark SQL空值Null,NaN判断和处理
[designmode] adapter pattern
Power query data format conversion, Split Merge extraction, delete duplicates, delete errors, transpose and reverse, perspective and reverse perspective
Yolov5、Pycharm、Anaconda环境安装
Knowledge about the memory size occupied by the structure
curlpost-php