PHP基于curl模拟post提交json数据示例
本文实例讲述了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;
functionhttp_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);
returnarray($return_code,$return_content);
}
PS:这里再为大家推荐几款比较实用的json在线工具供大家参考使用:
在线
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语