Google 地图 api "directions" 返回的 HTTP 响应代码:400
Google map api "directions" returned HTTP response code: 400
我正在尝试使用 java/grails 中的 webservices
获取 Google 方向 API 的结果,但出现错误
IOException occurred when processing request: Server returned HTTP
response code: 400 for URL:
http://maps.googleapis.com/maps/api/directions/json?origin=Anand
Nagar, Shri Krupa Society, Old Sangvi, Pimpri-Chinchwad, Maharashtra
411027&destination=Unnamed Road, Bopkhel, Pune, Maharashtra 411031,
India. Stacktrace follows: Message: Server returned HTTP response
code: 400 for URL:
http://maps.googleapis.com/maps/api/directions/json?origin=Anand
Nagar, Shri Krupa Society, Old Sangvi, Pimpri-Chinchwad, Maharashtra
411027&destination=Unnamed Road, Bopkhel, Pune, Maharashtra 411031,
India
如有遗漏请指出
注意:如果直接在浏览器中使用,相同 URL 效果很好
您需要HTML 对字符串进行编码。如果像现在一样形成 Raw URL 字符串,则 Anand 和 Nagar 之间存在 space 等等,这是不允许的。
示例 - 对任何主题进行 google 搜索,注意 space 在 URL 中被替换为 + 或 %20。
即使您在浏览器中粘贴相同的 URL,它也能正常工作。但是请注意 URL,space 应该更改为 + 或 %20。那是因为我们的浏览器应用程序为我们做了 URL 编码。
我正在尝试使用 java/grails 中的 webservices
获取 Google 方向 API 的结果,但出现错误
IOException occurred when processing request: Server returned HTTP response code: 400 for URL: http://maps.googleapis.com/maps/api/directions/json?origin=Anand Nagar, Shri Krupa Society, Old Sangvi, Pimpri-Chinchwad, Maharashtra 411027&destination=Unnamed Road, Bopkhel, Pune, Maharashtra 411031, India. Stacktrace follows: Message: Server returned HTTP response code: 400 for URL: http://maps.googleapis.com/maps/api/directions/json?origin=Anand Nagar, Shri Krupa Society, Old Sangvi, Pimpri-Chinchwad, Maharashtra 411027&destination=Unnamed Road, Bopkhel, Pune, Maharashtra 411031, India
如有遗漏请指出
注意:如果直接在浏览器中使用,相同 URL 效果很好
您需要HTML 对字符串进行编码。如果像现在一样形成 Raw URL 字符串,则 Anand 和 Nagar 之间存在 space 等等,这是不允许的。
示例 - 对任何主题进行 google 搜索,注意 space 在 URL 中被替换为 + 或 %20。
即使您在浏览器中粘贴相同的 URL,它也能正常工作。但是请注意 URL,space 应该更改为 + 或 %20。那是因为我们的浏览器应用程序为我们做了 URL 编码。