首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nominatim应用程序错误PHP

Nominatim应用程序错误PHP
EN

Stack Overflow用户
提问于 2016-09-12 14:06:57
回答 1查看 2K关注 0票数 3

我有PHP应用程序,它发送的地理编码的url请求:

代码语言:javascript
复制
http://nominatim.openstreetmap.org/reverse?format=xml&lat=33&lon=34&addressdetails=1

当我复制到浏览器时,返回XML响应。当从PHP文件发送的相同url的响应为:

代码语言:javascript
复制
<html><head><title>Bandwidth limit exceeded</title></head><body><h1>Bandwidth limit exceeded</h1><p>You have been temporarily blocked because you have been overusing OSM's geocoding service or because you have not provided sufficient identification of your application. This block will be automatically lifted after a while. Please take the time and adapt your scripts to reduce the number of requests and make sure that you send a valid UserAgent or Referer.</p><p>For more information, consult the <a href="http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy">usage policy</a> for the OSM Nominatim server.</body></head>

该请求每5分钟发送一次,不违反1秒最短时间。请求限制。如何避免出现该错误消息?

代码语言:javascript
复制
// Send to nomintaim server reverse geocoding request 
    $url = "http://nominatim.openstreetmap.org/reverse?format=xml&lat=" . $loc['lat'] . "&lon=" . $loc['lng']. "&addressdetails=1";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    $result = curl_exec($ch);
    curl_close($ch);
EN

回答 1

Stack Overflow用户

发布于 2018-02-05 16:26:49

您应该像这样使用CURLOPT_USERAGENT & CURLOPT_REFERER:

代码语言:javascript
复制
$userAgent = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2';
curl_setopt( $ch, CURLOPT_USERAGENT, $userAgent );
curl_setopt($ch, CURLOPT_REFERER, 'http://www.example.com/1');
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39444215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档