问题是在Unirest.get的url中转义大括号

时间:2017-03-14 23:15:48

标签: java rest unirest

我正在尝试检索此休息端点的结果:

http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer/distance?sr=4326&geometry1={"geometryType":"esriGeometryPoint","geometry":{"x":43.5664375,"y":1.4675999}}&geometry2={"geometryType":"esriGeometryPoint","geometry":{"x":49.120329,"y":6.164786}}&geodesic=true&f=pjson

以下是我的工作方式:

 String geometry1 = "geometry1={\"geometryType\":\"esriGeometryPoint\",\"geometry\":{\"x\":43.5664375,\"y\":1.4675999}}";
 String geometry2 = "geometry2={\"geometryType\":\"esriGeometryPoint\",\"geometry\":{\"x\":49.120329,\"y\":6.164786}}";

 try {
        response5 = Unirest.get("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer/distance?sr=4326&{geometry1}&{geometry2}&geodesic=true&f=pjson")
                .routeParam("geometry1", geometry1)
                .routeParam("geometry2", geometry2)
                .asJson();
    } catch (UnirestException e) {
        e.printStackTrace();
    }

但是我得到了这个错误,其中非法字符是我的网址的第一个大括号:geomtry1={

Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in query at index 122

如何摆脱花括号?我试过了URLEncoder.encode。这逃脱了大括号,但似乎没有正确格式化url因为我得到错误:geometry1' must be specified","'geometry2' must be specified

0 个答案:

没有答案