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 婆婆高寿祝福语大全简短