你有空
$_POST。如果您的网络服务器希望以json格式查看数据,则需要读取原始输入,然后使用JSON解码对其进行解析。
您需要这样的东西:
$json = file_get_contents('php://input');$obj = json_depre($json);另外,您使用错误的代码来测试JSON通信…
CURLOPT_POSTFIELDS告诉
curl您将参数编码为
application/x-www-form-urlenpred。您需要在这里使用JSON字符串。
更新
您的测试页php代码应如下所示:
$data_string = json_enpre($data);$ch = curl_init('http://webservice.local/');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);$result = json_depre($result);var_dump($result);同样,在您的Web服务页面上,您应该删除其中一行
header('Content-type: application/json');。它只能被调用一次。


