当前位置:网站首页>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)];}边栏推荐
- Key structure of ffmpeg - avframe
- 常用API类及异常体系
- Determinant learning notes (I)
- DEJA_ Vu3d - cesium feature set 055 - summary description of map service addresses of domestic and foreign manufacturers
- FFMPEG关键结构体——AVFrame
- [designmode] adapter pattern
- Solve the problem of reading Chinese garbled code in sqlserver connection database
- AtCoder Beginner Contest 258【比赛记录】
- STM32 configuration after chip replacement and possible errors
- Model analysis of establishment time and holding time
猜你喜欢

Calculate sha256 value of data or file based on crypto++

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

MySQL之函数

notepad++正則錶達式替換字符串

MySql——CRUD

Go learning - dependency injection

Date类中日期转成指定字符串出现的问题及解决方法

FFT learning notes (I think it is detailed)

How to use the flutter framework to develop and run small programs

Hudi of data Lake (1): introduction to Hudi
随机推荐
如何制作自己的机器人
如何利用Flutter框架开发运行小程序
Reading notes of the beauty of programming
LeetCode 6006. Take out the least number of magic beans
【线上小工具】开发过程中会用到的线上小工具合集
MySQL之函数
How to use the flutter framework to develop and run small programs
SQLServer连接数据库读取中文乱码问题解决
Spark AQE
uniapp开发,打包成H5部署到服务器
Classical concurrency problem: the dining problem of philosophers
Knowledge about the memory size occupied by the structure
Calculate sha256 value of data or file based on crypto++
2022-02-13 work record -- PHP parsing rich text
Folding and sinking sand -- weekly record of ETF
LeetCode 1189. Maximum number of "balloons"
Ffmpeg learning - core module
State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
Problems and solutions of converting date into specified string in date class
MySQL storage engine