【问题标题】:Spring Rest Template Url contains complex querySpring Rest Template Url 包含复杂的查询
【发布时间】:2015-07-23 08:54:36
【问题描述】:

我想调用一个接受 url 查询参数的 Web 服务。 这是查询:

{PK} IN({{Select {o.name}  from {Student! as o} where {o.name} IN ({{Select {s.pk} 
 from {School as s} where {s.code}="school"}})}})

我使用this对查询进行编码

我将编码后的查询放入 Web 服务 url:http://host?query=query_above_encoded

所以当你这样做时(使用resttemplate调用网络服务):

ResponseEntity<Model> response = restTemplate.exchange(
                    url, HttpMethod.GET, request, Model.class);

我得到了这个例外:

org.springframework.web.client.HttpServerErrorException: 500 Erreur Interne de Servlet

但是当我使用休息客户端应用程序(作为邮递员)调用相同的 url 时,会得到响应。

有人有什么想法吗?

【问题讨论】:

    标签: java spring rest url-encoding resttemplate


    【解决方案1】:

    解决办法是在url编码后使用URI JAVA对象:

    ResponseEntity<Model> response = restTemplate.exchange(
                        new URI(encodedUrl), HttpMethod.GET, request, Model.class);
    

    希望这对其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-12-22
      • 1970-01-01
      • 2013-07-22
      • 1970-01-01
      • 1970-01-01
      • 2016-10-26
      • 2022-10-14
      • 2012-10-18
      • 1970-01-01
      相关资源
      最近更新 更多