当前位置:网站首页>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)];}
边栏推荐
- notepad++正则表达式替换字符串
- Global and Chinese market of water heater expansion tank 2022-2028: Research Report on technology, participants, trends, market size and share
- 如何制作自己的机器人
- Spark-SQL UDF函数
- LeetCode 1598. Folder operation log collector
- 【线上小工具】开发过程中会用到的线上小工具合集
- 云导DNS和知识科普以及课堂笔记
- [groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)
- FFT learning notes (I think it is detailed)
- Spark SQL null value, Nan judgment and processing
猜你喜欢
Room cannot create an SQLite connection to verify the queries
Room cannot create an SQLite connection to verify the queries
[designmode] Decorator Pattern
XML配置文件
Determinant learning notes (I)
Location based mobile terminal network video exploration app system documents + foreign language translation and original text + guidance records (8 weeks) + PPT + review + project source code
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
uniapp开发,打包成H5部署到服务器
Free chat robot API
常用API类及异常体系
随机推荐
Ffmpeg captures RTSP images for image analysis
devkit入门
7.5 decorator
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
The global and Chinese markets of dial indicator calipers 2022-2028: Research Report on technology, participants, trends, market size and share
About the slmgr command
Hudi of data Lake (2): Hudi compilation
Browser local storage
[groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)
Folding and sinking sand -- weekly record of ETF
notepad++正則錶達式替換字符串
How spark gets columns in dataframe --column, $, column, apply
Ffmpeg learning - core module
[designmode] composite mode
从底层结构开始学习FPGA----FIFO IP核及其关键参数介绍
Power query data format conversion, Split Merge extraction, delete duplicates, delete errors, transpose and reverse, perspective and reverse perspective
建立时间和保持时间的模型分析
如何利用Flutter框架开发运行小程序
Leetcode Fibonacci sequence
Uniapp development, packaged as H5 and deployed to the server