mat*_*e09 11 php rest get openstreetmap
我是PHP的新手,也是使用RESTful API的全部内容.我现在想做的就是成功向OpenStreetMap API发出一个纯HTTP GET请求.
我正在使用tcdent的简单PHP REST客户端,我基本上了解它的功能.我在OSM中获取当前Changeset的示例代码是:
<?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;
?>
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中输入URL"http://api.openstreetmaps.org/api/0.6/changesets"时,它会传递XML文件.但是,通过此PHP代码,它将返回OSM 404 File not Found页面.
我想这是一个相当愚蠢的PHP新手问题,但我看不出我错过了什么,因为我对所有这些客户端 - 服务器端进程等知之甚少.
谢谢你的帮助!
Mar*_*ein 15
使用卷曲.见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" => 'lorna@example.com',
);
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);
Run Code Online (Sandbox Code Playgroud)
$ xml = new SimpleXMLElement($ curl_response);
| 归档时间: |
|
| 查看次数: |
40592 次 |
| 最近记录: |