最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
PHP基于curl模拟post提交json数据示例
时间:2022-06-24 14:35:16 编辑:袖梨 来源:一聚教程网
本文实例讲述了PHP基于curl模拟post提交json数据。分享给大家供大家参考,具体如下:
这里php模拟post提交json数据操作的关键是在头部设置Content-Type
"test001",
"pass"=>"xxxx",
);
$data = json_encode($param);
list($return_code, $return_content) = http_post_data($url, $data);//return_code是http状态码
print_r($return_content);exit;
function http_post_data($url, $data_string) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json; charset=utf-8",
"Content-Length: " . strlen($data_string))
);
ob_start();
curl_exec($ch);
$return_content = ob_get_contents();
ob_end_clean();
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return array($return_code, $return_content);
}
相关文章
- 吉利汽车2026上半年“量价利齐升”:营收破1700亿 海外销量激增158% 08-18
- 两个结构化数据自检工具的分工:语法校验与效果预览 08-18
- 元旦放假通知模板:清晰简洁的放假安排与温馨祝福 08-18
- 和平精英海岛 2.0 更新奖励是什么 08-18
- excel表格如何利用VBA代码插入交叉矩形图 08-18
- 客户续签率下滑?这套反馈管理,让客户粘性提高80% 08-18