当前位置:网站首页>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)];}边栏推荐
- Set data real-time update during MDK debug
- OpenCV经典100题
- [QT] QT uses qjson to generate JSON files and save them
- An understanding of & array names
- 猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
- XML Configuration File
- Gd32f4xx UIP protocol stack migration record
- Folding and sinking sand -- weekly record of ETF
- MDK debug时设置数据实时更新
- Comment faire votre propre robot
猜你喜欢

Knowledge about the memory size occupied by the structure

notepad++正则表达式替换字符串

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

Hudi of data Lake (1): introduction to Hudi

Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?

时间戳的拓展及应用实例

Key structure of ffmpeg - avframe

The relationship between FPGA internal hardware structure and code

Free chat robot API

anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
随机推荐
synchronized 和 ReentrantLock
Spark DF adds a column
Search (DFS and BFS)
Ffmpeg captures RTSP images for image analysis
NLP generation model 2017: Why are those in transformer
STM32按键消抖——入门状态机思维
免费的聊天机器人API
[designmode] composite mode
Arduino hexapod robot
Key structure of ffmpeg - avformatcontext
Room cannot create an SQLite connection to verify the queries
孤勇者
Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
7.5 decorator
MySQL storage engine
[Online gadgets] a collection of online gadgets that will be used in the development process
常用API类及异常体系
Atcoder beginer contest 258 [competition record]
Atcoder beginer contest 254 [VP record]
LeetCode 6006. Take out the least number of magic beans