雅虎地图 api 卷曲设置
我应该如何配置 cURL 以从 yahoo 地图 api 检索数据?
当前代码
curl_setopt($ch, CURLOPT_TIMEOUT, 5000);
curl_setopt($ch, CURLOPT_URL, $geocodeurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
以下是返回 400 - Bad request HTML 文件的 。我检查了 $geocodeurl
并且它是一个有效的 XML 文件,所以我认为问题一定是 cURL 选项?
$geocodeurl 是
http://where.yahooapis.com/geocode?appid=** My App ID **&q=Battle%20Creek,MI&gflags=R
How should I configure cURL to retrieve data from the yahoo maps api?
Here is the current code
curl_setopt($ch, CURLOPT_TIMEOUT, 5000);
curl_setopt($ch, CURLOPT_URL, $geocodeurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
Which returns a 400 - Bad request HTML file. I've checked $geocodeurl
and it is a valid XML file, so I figure the problem must be the cURL options?
$geocodeurl is
http://where.yahooapis.com/geocode?appid=** My App ID **&q=Battle%20Creek,MI&gflags=R
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我编写了一个简单的类包装器来获取基本地址作为 php 对象,这可能会帮助您完成工作!我还添加了一个谷歌地理编码包装器。
要回答您的问题,您发布的网址一切正常,但是,正如您在回复中提到的那样,您应该对参数进行urlencode,
这里是我的包装类的链接
https://github.com/mrpollo/Geocoding-API
i wrote a simple class wrapper to get a basic address as a php object, which might help you get the job done! i also added a google geocoding wrapper.
to answer your question, everything is ok with the url you posted, but yes as you mentioned on your reply you should urlencode the params
here is a link to my wrapper class
https://github.com/mrpollo/Geocoding-API
好吧,像往常一样,我错误地识别了问题。
cURL
没问题,但是q=
变量没有正确地通过任何类型的urlencode
函数传递。在我的浏览器中工作,因为 Firefox 善意地将
更改为
%20
。使用cURL
你需要更加小心。 。 。 。OK as usual I had misidentified the problem.
cURL
was fine, but theq=
variable was not being passed through any sort ofurlencode
function correctly.Worked in my browser because Firefox kindly changed the
to
%20
. WithcURL
you need to be more careful. . . .