当前位置:网站首页>Curlpost PHP
Curlpost PHP
2022-07-06 00:36:00 【Owenzhang24】
/** * AdoptionCURLEnvoyerHTTPDemande * * @param string $url //DemandeURL * @param array $postFields //Paramètres de demande * @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' //jsonVersion à remplir Content-Type: application/json; ) ); curl_setopt($ch, CURLOPT_HEADER, false);//Ne pas retourner les informations d'en - tête curl_setopt($ch, CURLOPT_POST, 1); if ($data != null) { curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Les résultats sont - ils affichés? ,1Ne pas afficher,0Afficher //Déterminer sihttps 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)];}边栏推荐
猜你喜欢

Classical concurrency problem: the dining problem of philosophers

Model analysis of establishment time and holding time

Introduction of motor

The relationship between FPGA internal hardware structure and code

Basic introduction and source code analysis of webrtc threads

关于slmgr命令的那些事

Priority queue (heap)

如何制作自己的机器人

Spark AQE

常用API类及异常体系
随机推荐
Solve the problem of reading Chinese garbled code in sqlserver connection database
The relationship between FPGA internal hardware structure and code
[simple implementation of file IO]
MySQL存储引擎
What is information security? What is included? What is the difference with network security?
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
LeetCode 6005. The minimum operand to make an array an alternating array
Codeforces round 804 (Div. 2) [competition record]
MDK debug时设置数据实时更新
Single source shortest path exercise (I)
2022-02-13 work record -- PHP parsing rich text
devkit入门
How to make your own robot
Spark SQL null value, Nan judgment and processing
MySql——CRUD
Extracting profile data from profile measurement
uniapp开发,打包成H5部署到服务器
时间戳的拓展及应用实例
详细页返回列表保留原来滚动条所在位置
[groovy] JSON string deserialization (use jsonslurper to deserialize JSON strings | construct related classes according to the map set)