当前位置:网站首页>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)];}
边栏推荐
- 【文件IO的简单实现】
- Mysql - CRUD
- Set data real-time update during MDK debug
- Determinant learning notes (I)
- curlpost-php
- 【DesignMode】装饰者模式(Decorator pattern)
- LeetCode 6005. The minimum operand to make an array an alternating array
- JS can really prohibit constant modification this time!
- Leetcode:20220213 week race (less bugs, top 10% 555)
- Spark SQL null value, Nan judgment and processing
猜你喜欢
数据分析思维分析方法和业务知识——分析方法(二)
Spark AQE
【DesignMode】组合模式(composite mode)
uniapp开发,打包成H5部署到服务器
Date类中日期转成指定字符串出现的问题及解决方法
Comment faire votre propre robot
从 1.5 开始搭建一个微服务框架——调用链追踪 traceId
Classic CTF topic about FTP protocol
[EI conference sharing] the Third International Conference on intelligent manufacturing and automation frontier in 2022 (cfima 2022)
免费的聊天机器人API
随机推荐
【文件IO的简单实现】
Notepad + + regular expression replace String
Comment faire votre propre robot
孤勇者
免费的聊天机器人API
Common API classes and exception systems
Opencv classic 100 questions
Cloud guide DNS, knowledge popularization and classroom notes
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
MySQL存储引擎
《编程之美》读书笔记
【DesignMode】组合模式(composite mode)
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
MySQL storage engine
Global and Chinese markets of universal milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
如何制作自己的機器人
Yolov5, pychar, Anaconda environment installation
[simple implementation of file IO]
LeetCode 1598. Folder operation log collector
[EI conference sharing] the Third International Conference on intelligent manufacturing and automation frontier in 2022 (cfima 2022)