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 红包祝福语简短10字
18 周六早晨祝福语简短