【发布时间】:2016-09-05 10:12:40
【问题描述】:
我是 Web 服务的新手,我已经成功创建了一个 Web 服务,现在我想使用我创建的 Web 服务,但是在使用 json 解码后我得到一个空值,我已经执行了 json_last_error(),并且我得到 0,我想这意味着没有错误,有人可以向我解释为什么我的请求 Web 服务正在运行得到一个空值。下面是我使用网络服务的代码。
<?php if(isset($_POST['submit'])){
$name = isset($_POST['name']);
$url ="http://localhost/htdocs/my_service/index_rest.php/$name"; // send request resource
$c = curl_init($url); //get response
curl_setopt($c,CURLOPT_RETURNTRANSFER,true);
//curl_setopt($c,CURLOPT_POST,$data);
$response = curl_exec($c);
echo $response; //decode response
$result = json_decode($response);
echo "</br>Data = : ".$result->data."</br>"; //equals 0, meaning error is none or no json error
echo json_last_error();
}
?>
【问题讨论】:
-
回显响应并检查它是否正确格式化输出,它不应包含任何额外的空格,还要验证它是否被重定向
-
var_dump($response);输出是什么?
标签: php json web-services curl