解决方案 »

  1.   

    你有 Content-Type: application/json 的 mime 的类型声明
    php 将不会自行解释传入的数据,需要你自己完成
    传入的数据
    $input = file_get_contents('php://input');
    是这样的:{"name":"Hagrid","age":"36"}
    你可根据 $_SERVER['CONTENT_TYPE'] 项来选择解析的方法,你这里是:application/json
      

  2.   

    可以使用curl 传json 数据么?
      

  3.   

    你看下是http传还是https传,然后需不需要模拟头部部分信息?
    像这个样子的:
    header('Host:a1.easemob.com');
            header('Accept:application/json;');
            header('Content-Type:application/json;');
    不知道你具体想要啥样的。
      

  4.   

    发送<?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));