php curl 传 json 数据实例 phpjsoncurl 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你有 Content-Type: application/json 的 mime 的类型声明php 将不会自行解释传入的数据,需要你自己完成传入的数据$input = file_get_contents('php://input');是这样的:{"name":"Hagrid","age":"36"}你可根据 $_SERVER['CONTENT_TYPE'] 项来选择解析的方法,你这里是:application/json 可以使用curl 传json 数据么? 你看下是http传还是https传,然后需不需要模拟头部部分信息?像这个样子的:header('Host:a1.easemob.com'); header('Accept:application/json;'); header('Content-Type:application/json;');不知道你具体想要啥样的。 发送<?php$data = array("name" => "Hagrid", "age" => "36");$data_string = json_encode($data); $ch = curl_init('http://localhost/server.php');curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data_string))); $result = curl_exec($ch);echo $result;?>接收 server.php$streamData = isset($GLOBALS['HTTP_RAW_POST_DATA'])? $GLOBALS['HTTP_RAW_POST_DATA'] : '';if(empty($streamData)){ $streamData = file_get_contents('php://input');}var_dump(json_decode($streamData,true)); 我用 php 的 curl 采集的图片为0kb, 请大侠帮忙看看, 谢了. 程序问题,大家来看看~~ 上传php 工程到服务器的问题 请教 南北互通 得到当前日期前n天的日期,有没有什么比较好的方法? 我有个外包项目,谁有兴趣?(限上海地区) 接口,如何取得对方返回XML的某个节点值 问一个正则表达式的问题 求助!PHP执行session_register("regid")时出以下错误!在线等 给分!!!!!!!!!!!!wasy!!!!!! jquery的ajax返回不了json数据 php普通的表单增加
php 将不会自行解释传入的数据,需要你自己完成
传入的数据
$input = file_get_contents('php://input');
是这样的:{"name":"Hagrid","age":"36"}
你可根据 $_SERVER['CONTENT_TYPE'] 项来选择解析的方法,你这里是:application/json
像这个样子的:
header('Host:a1.easemob.com');
header('Accept:application/json;');
header('Content-Type:application/json;');
不知道你具体想要啥样的。
$data = array("name" => "Hagrid", "age" => "36");
$data_string = json_encode($data);
$ch = curl_init('http://localhost/server.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);echo $result;
?>
接收 server.php$streamData = isset($GLOBALS['HTTP_RAW_POST_DATA'])? $GLOBALS['HTTP_RAW_POST_DATA'] : '';if(empty($streamData)){
$streamData = file_get_contents('php://input');
}var_dump(json_decode($streamData,true));