curl post 用json方式
2024-08-24 14:46:39
if(!function_exists('tps_curl_post3')){
function tps_curl_post3($url, $postData) {
$postData = json_encode($postData);
$curl = curl_init(); //初始化
curl_setopt($curl,CURLOPT_URL,$url); //设置url
curl_setopt($curl,CURLOPT_HTTPAUTH,CURLAUTH_BASIC); //设置http验证方法
curl_setopt($curl, CURLOPT_TIMEOUT,30);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); //设置curl_exec获取的信息的返回方式
curl_setopt($curl,CURLOPT_POST,1); //设置发送方式为post请求
curl_setopt($curl,CURLOPT_POSTFIELDS,$postData); //设置post的数据 curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($postData))
); $result = curl_exec($curl);
curl_close($curl);
return json_decode($result,true);
}
}
最新文章
- iOS之 Xcode7下 bitcode的工作流程及安全评估
- C#方法的六种参数,值参数、引用参数、输出参数、参数数组、命名参数、可选参数
- 【JAVA、C++】LeetCode 013 Roman to Integer
- Android -- Support包特性
- 【转】Newtonsoft.Json 的序列化与反序列化
- App是什么,可以分为几类?及其相关解释。
- (Step by Step)How to setup IP Phone Server(VoIP Server) for free.
- HDU5437 Alisha’s Party (优先队列 + 模拟)
- 深度分析 Java 的 ClassLoader 机制(源码级别)(转)
- Codeforces 383C . Propagating tree【树阵,dfs】
- (@WhiteTaken)设计模式学习——抽象工厂模式
- jQuery选择器的分类之过滤选择器
- STL中队列(queue)的使用方法
- Python 爬虫练习(三) 利用百度进行子域名收集
- android 开发之 ListView 与Adapter 应用实践
- vue中import引入模块路径中@符号是什么意思
- Xilinx FPGA开发随笔
- IDEA 不识别的MAVEN 项目应如何处理
- Python全栈之路----数据类型—列表
- Codeforces 750E New Year and Old Subsequence - 线段树 - 动态规划