如何从PHP中的休息中获取信息?

时间:2014-07-10 05:27:32

标签: php rest

如何从php中的休息中获取信息?

我有url,我想通过php从网络服务中提取信息。

2 个答案:

答案 0 :(得分:1)

调用GET请求的示例

//next example will recieve all messages for specific conversation
$service_url = 'http://example.com/api/conversations/[CONV_CODE]/messages&apikey=[API_KEY]';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
    $info = curl_getinfo($curl);
    curl_close($curl);
    die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
    die('error occured: ' . $decoded->response->errormessage);
}
echo 'response ok!';
var_export($decoded->response);

参考:How to make REST calls in PHP

答案 1 :(得分:0)

如果您的主机已启用,则可以执行curl