当前位置:网站首页>curlpost-php
curlpost-php
2022-07-06 00:36: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)];}边栏推荐
- How spark gets columns in dataframe --column, $, column, apply
- Pointer - character pointer
- [Chongqing Guangdong education] Chongqing Engineering Vocational and Technical College
- Go learning --- read INI file
- MySql——CRUD
- Arduino六足机器人
- Calculate sha256 value of data or file based on crypto++
- Spark获取DataFrame中列的方式--col,$,column,apply
- Multithreading and high concurrency (8) -- summarize AQS shared lock from countdownlatch (punch in for the third anniversary)
- Folding and sinking sand -- weekly record of ETF
猜你喜欢

Model analysis of establishment time and holding time

Classic CTF topic about FTP protocol

Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)

Leetcode 450 deleting nodes in a binary search tree

MySQL functions

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

数据分析思维分析方法和业务知识——分析方法(三)

免费的聊天机器人API

MySQL storage engine

Room cannot create an SQLite connection to verify the queries
随机推荐
wx. Getlocation (object object) application method, latest version
LeetCode 6004. Get operands of 0
Extracting profile data from profile measurement
synchronized 和 ReentrantLock
Determinant learning notes (I)
LeetCode 1598. Folder operation log collector
免费的聊天机器人API
AtCoder Beginner Contest 254【VP记录】
Browser local storage
Idea远程提交spark任务到yarn集群
notepad++正則錶達式替換字符串
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
Spark-SQL UDF函数
How to use the flutter framework to develop and run small programs
XML Configuration File
NLP text processing: lemma [English] [put the deformation of various types of words into one form] [wet- > go; are- > be]
Yolov5、Pycharm、Anaconda环境安装
Global and Chinese markets of universal milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
About the slmgr command
NLP generation model 2017: Why are those in transformer