我正在尝试针对 local.yahooapis.com 地理编码接口发出地理编码请求。这是昨天工作的,具有相同的 AppID 和硬编码的地址。现在我已经分解了查询字符串并以编程方式从数据库中填充它。api 返回 403 - 禁止错误。我不确定我是否遇到了一些限制,或者在重构时弄乱了我的请求。
请求,用“MY_APP_ID”替换:
Warning: file_get_contents(http://local.yahooapis.com/MapsService/V1/geocode?appid=MY_APP_ID&street=6727+N+5TH+ST&city=PHILADELPHIA&state=PA&output=php) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden
以及整个来回的wireshark:
GET /MapsService/V1/geocode?appid=MY_APP_ID&street=BOX+269&city=TOUGHKENAMON&state=PA&output=php HTTP/1.0
Host: local.yahooapis.com
HTTP/1.1 403 Forbidden
Date: Mon, 19 Jul 2010 14:46:42 GMT
P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Yahoo! - 403 Forbidden</title><style>
/* nn4 hide */
/*/*/
body {font:small/1.2em arial,helvetica,clean,sans-serif;font:x-small;text-align:center;}table {font-size:inherit;font:x-small;}
html>body {font:83%/1.2em arial,helvetica,clean,sans-serif;}input {font-size:100%;vertical-align:middle;}p, form {margin:0;padding:0;}
p {padding-bottom:6px;margin-bottom:10px;}#doc {width:48.5em;margin:0 auto;border:1px solid #fff;text-align:center;}#ygma {text-align:right;margin-bottom:53px}
#ygma img {float:left;}#ygma div {border-bottom:1px solid #ccc;padding-bottom:8px;margin-left:152px;}#bd {clear:both;text-align:left;width:75%;margin:0 auto 20px;}
h1 {font-size:135%;text-align:center;margin:0 0 15px;}legend {display:none;}fieldset {border:0 solid #fff;padding:.8em 0 .8em 4.5em;}
form {position:relative;background:#eee;margin-bottom:15px;border:1px solid #ccc;border-width:1px 0;}
#s1p {width:15em;margin-right:.1em;}
form span {position:absolute;left:70%;top:.8em;}form a {font:78%/1.2em arial;display:block;padding-left:.8em;white-space:nowrap;background: url(http://us.i1.yimg.com/us.yimg.com/i/s/bullet.gif) no-repeat left center;}
form .sep {display:none;}.more {text-align:center;}#ft {padding-top:10px;border-top:1px solid #999;}#ft p {text-align:center;font:78% arial;}
/* end nn4 hide */
</style></head>
<body><div id="doc">
<div id="ygma"><a href="http://us.rd.yahoo.com/403/*http://www.yahoo.com"><img
src=http://us.i1.yimg.com/us.yimg.com/i/yahoo.gif
width=147 height=31 border=0 alt="Yahoo!"></a><div><a
href="http://us.rd.yahoo.com/403/*http://www.yahoo.com">Yahoo!</a>
- <a href="http://us.rd.yahoo.com/403/*http://help.yahoo.com">Help</a></div></div>
<div id="bd"><h1>Sorry, Forbidden.</h1>
You don't have permission to access this URL on this server.<P>
<P>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.
<p>Please check the URL for proper spelling and capitalization. If
you're having trouble locating a destination on Yahoo!, try visiting the
<strong><a
href="http://us.rd.yahoo.com/403/*http://www.yahoo.com">Yahoo! home
page</a></strong> or look through a list of <strong><a
href="http://us.rd.yahoo.com/403/*http://docs.yahoo.com/docs/family/more/">Yahoo!'s
online services</a></strong>. Also, you may find what you're looking for
if you try searching below.</p>
<form name="s1" action="http://us.rd.yahoo.com/403/*-http://search.yahoo.com/search"><fieldset>
<legend><label for
你能找出我做错了什么,或者告诉我在哪里可以检查我的 AppID 是否有任何新的限制?
更新:
我尝试了一个全新的应用程序。我在脚本中使用了 5 秒的睡眠时间,并且只发出了 3 个请求。第一个请求失败了。现在不知道是什么导致了这个问题。
警告:file_get_contents(http://local.yahooapis.com/MapsService/V1/geocode?appid=orQG_ZLV34EmNvmFaIKpOd5RSu1aBsDEfoxNeJBFhr5VUM5dItKbyXLjoMYi0Q--&street=6727+N+5TH+ST&city=PHILADELPHIA&state=PA&output=php)[function.file-get-contents] :打开流失败:HTTP 请求失败!HTTP/1.1 403 Forbidden in C:\wamp\www\Smartphone\updategeo.php on line 23 1 警告:file_get_contents( http://local.yahooapis.com/MapsService/V1/geocode?appid=orQG_ZLV34EmNvmFaIKpOd5RSu1aBsDEfoxNeJBFhr5VUM5dItKbyXLjoMYi0Q--&street=7400 +OXFORD+AVE&city=PHILADELPHIA&state=PA&output=php ) [function.file-get-contents]:打开流失败:HTTP 请求失败!HTTP/1.1 403 Forbidden in C:\wamp\www\Smartphone\updategeo.php on line 23 2 警告:file_get_contents(http://local.yahooapis.com/MapsService/V1/geocode?appid=orQG_ZLV34EmNvmFaIKpOd5RSu1aBsDEfoxNeJBFhr5VUM5dItKbyXLjoMYi0Q--&street=2+W+FOURTH+ST&city=BRIDGEPORT&state=PA&output=php ) [function.file-get-contents]: 无法打开流:HTTP 请求失败!HTTP/1.1 403 Forbidden in C:\wamp\www\Smartphone\updategeo.php on line 23 3
再次编辑:我最好的猜测是,因为我正在开发一个开发框,并且 appId 是为不同的域生成的,所以它拒绝了它。我如何确定这是否正确?但这对我来说没有 100% 的意义,因为这段代码在某些时候确实有效。