【问题标题】:Spring RestTemplate throws IllegalArgumentException: not a valid HTTP URLSpring RestTemplate 抛出 IllegalArgumentException:不是有效的 HTTP URL
【发布时间】:2011-10-20 18:31:05
【问题描述】:

java.lang.IllegalArgumentException: [https://localhost/pcap/search?stime=20110930%2E000000&etime=20110930%2E235959&bpf=tcp

这是我使用 Spring RestFul 模板进行的调用:

final PcapSearchResponse pcapSearchResult = restTemplate.postForObject(
    nPulseApiUris.get(2), null, PcapSearchResponse.class, sTime, eTime, bpf);

我不明白为什么这是一个错误的 URL?我使用 UTF-8 对“.”进行编码。字符,但我不确定为什么我的 URL 仍然无效。

非常感谢您的帮助!

感谢您的帮助!!!

【问题讨论】:

    标签: java spring rest spring-mvc resttemplate


    【解决方案1】:

    RestTemplate 的文档提到:

    此外,字符串参数方法假定 URL 字符串未编码。

    因此,当您将 URL 作为字符串传递时,不要对其进行编码。 Spring 会解决这个问题。

    【讨论】:

    • 您好 Bozho,非常感谢您的回复。是的,我没有对网址进行编码。 URL 在我的代码中如下所示,其中 nPulseApiUris 的类型为 Listhttps://localhost/pcap/search?stime={stime}&etime=${etime}&bpf=${bpf} 非常感谢您的帮助!
    • 嗨@Bozho,非常感谢您的回复。我试图发布到 RESTful 服务 URI https://localhost/pcap/search的请求参数是:stime=20110930.000000 etime=20110930.235959 bpf=tcp 非常感谢 Bozho!
    • 看起来不错。现在摆脱 amp
    • 如果我去掉 & 符号,我不确定如何将这些参数发布到 RESTful 服务 URI。因此,我想如果我附加它,那会起作用。谢谢你的帮助!!
    • 不要删除整个 & 符号,但不要将其编码。所以& 而不是&
    猜你喜欢
    • 2021-06-09
    • 2014-04-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多