错误地理编码API

本文关键字:API 编码 错误 | 更新日期: 2023-09-27 17:50:50

我正在尝试使用谷歌地理编码。如果我只是键入

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true

它给了我正确的输出。我正试图将其与亚马逊代理服务器一起使用,它会提供

{ "error_message" : "The 'sensor' parameter specified in the request must be set to either 'true' or 'false'.", "results" : [], "status" : "REQUEST_DENIED" }

这是代码

http://ec2-00-000-000-000.compute-1.amazonaws.com/OsProxy/getpage.aspx?p=https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true

有人能帮我吗?

谢谢Rashmi

错误地理编码API

您需要对参数进行URL编码。考虑您正在使用的URL:

http://ec2-00-000-000-000.compute-1.amazonaws.com/OsProxy/getpage.aspx?p=https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true

这被解析为:

http://ec2-00-000-000-000.compute-1.amazonaws.com/OsProxy/getpage.aspx?
    p=https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&
    sensor=true

也就是说,您将sensor参数传递给amazonws.com,而不是googleapis.com

由于amazonws.com的唯一参数应该是完整的URL,因此对该URL进行编码,使其作为单个参数到达amazonws.com,并传递到googleapis.com:

http://ec2-00-000-000-000.compute-1.amazonaws.com/OsProxy/getpage.aspx?p=https%3A%2F%2Fmaps.googleapis.com%2Fmaps%2Fapi%2Fgeocode%2Fjson%3Faddress%3D1600%2BAmphitheatre%2BParkway%2C%2BMountain%2BView%2C%2BCA%26sensor%3Dtrue