我对 PHP 以及使用 RESTful API 的整个过程还很陌生。
我现在想要做的就是成功发出一个简单的 HTTP GET 请求
这开放街道地图 API.
我正在使用tcdent 的简单 PHP REST 客户端我基本上了解它的功能。我在 OSM 中获取当前变更集的示例代码是:
<?php
include("restclient.php");
$api = new RestClient(array(
'base_url' => "http://api.openstreetmaps.org/",
'format' => "xml")
);
$result = $api->get("api/0.6/changesets");
if($result->info->http_code < 400) {
echo "success:<br/><br/>";
} else {
echo "failed:<br/><br/>";
}
echo $result->response;
?>
当我在浏览器中输入 URL“http://api.openstreetmaps.org/api/0.6/changesets”时,它会传递 XML 文件。但是,通过此 PHP 代码,它会返回 OSM 404 File not Found 页面。
我想这是一个相当愚蠢的 PHP 新手问题,但我看不出我错过了什么,因为我(还)对所有这些客户端-服务器端进程等了解不多。
感谢您的帮助!
使用卷曲。看http://www.lornajane.net/posts/2008/using-curl-and-php-to-talk-to-a-rest-service
$service_url = 'http://example.com/rest/user/';
$curl = curl_init($service_url);
$curl_post_data = array(
"user_id" => 42,
"emailaddress" => '[email protected]',
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);
curl_close($curl);
$xml = new SimpleXMLElement($curl_response);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)