【问题标题】:Illegal character at query查询中的非法字符
【发布时间】:2013-10-08 05:36:59
【问题描述】:

我有一个应用程序需要向谷歌查询路线等。我最近重新组织了我的代码,做了一些优化来查询带有航点的路线,以减少请求发送计数。现在有一个问题:我得到
java.lang.IllegalArgumentException: Illegal character in query at index 146: http://maps.googleapis.com/maps/api/directions/json?origin=52.4000826,16.8928842&destination=52.4129715,16.8296386&waypoints=52.4053469,16.8969666|52.4049754,16.8811389&sensor=false

我相信索引 146 处的字符是“|”。这个角色有什么问题?

感谢您的建议。

这是我构建查询的代码:

try {
            String requestString = "http://maps.googleapis.com/maps/api/directions/"
                    + "json?origin="
                    + Double.toString(start.getLatitude())
                    + ","
                    + Double.toString(start.getLongitude())
                    + "&destination="
                    + Double.toString(end.getLatitude())
                    + "," + Double.toString(end.getLongitude());

            if (points.length > 2) {
                String waypoints = "&waypoints="
                        + Double.toString(points[1].getLatitude()) + ","
                        + Double.toString(points[1].getLongitude());
                for (int i = 2; i < points.length - 1; i++) {
                    waypoints = waypoints + "|"
                            + Double.toString(points[i].getLatitude())
                            + ","
                            + Double.toString(points[i].getLongitude());
                }
                requestString = requestString + waypoints;
            }
            requestString = requestString + "&sensor=false";

【问题讨论】:

  • 请出示您的代码。在那之前我们只能猜测。
  • 尝试 %7C 而不是管道。请参阅此SO postASCIITable.com

标签: java character illegal-characters


【解决方案1】:

UFL1138 是对的。替换“|”与“%7C”一起工作。谢谢

【讨论】:

  • 非常感谢,我损失了大约一个小时。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-25
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 2021-12-25
  • 2011-10-12
相关资源
最近更新 更多