gpt4 book ai didi

php - Nominatim 应用程序错误 PHP

转载 作者:行者123 更新时间:2023-12-04 16:47:02 26 4
gpt4 key购买 nike

我有 PHP 应用程序发送地址解析的 url 请求:

http://nominatim.openstreetmap.org/reverse?format=xml&lat=33&lon=34&addressdetails=1

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

<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 秒分钟。请求限制。如何避免出现该错误信息?

// 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);

最佳答案

你应该像这样使用 CURLOPT_USERAGENT 和 CURLOPT_REFERER :

$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');

关于php - Nominatim 应用程序错误 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39444215/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com