gpt4 book ai didi

Spring RestTemplate 初学者 : The request sent by the client was syntactically incorrect ()

转载 作者:行者123 更新时间:2023-12-04 18:23:02 28 4
gpt4 key购买 nike

我正在尝试访问可以使用 curl 对其进行测试的 Rest 资源
id 长度应为 11 个字符
如果 id 的长度小于 11 例如 '12345'
https://somesite.com:7677/something/id/ {id} iam 从我的 java 代码和 curl 中得到 404 HTTP 错误,这是预期的

如果 id 的长度等于 11 并且它是无效的 id
然后我从 curl 和 java 得到相同的响应

但是如果我给出 curl 已经存在的有效 id
我得到了正确的 json 响应,但是当我试图从 restTemplate 访问 Rest 资源时,它显示错误,如下所示

The request sent by the client was syntactically incorrect (). and there are no error logs for this request



从过去 2 天开始,我无法弄清楚,请提供您对此的想法,以便它对我真正有帮助
我的休息模板配置:
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<ref bean="jsonHttpMessageConverter" />
</list>
</property>
</bean>

我试图访问的代码是
public List<Account> getAccounts(PersonNumber personNumber) {
logger.warn("Inside getAccounts of TransferAgreement client");

String url = "https://somesite.com:7677/something/id/12345";
logger.warn("URL acessing "+personNumber.toString()+" URL "+ url);
String a = restTemplate.getForObject(url, String.class);
System.out.println(a);
return null;
}

最佳答案

假设您正在使用 Eclipse。

为 Spring 启用日志记录

  • 将日志级别设置为调试或跟踪 Spring,请参阅 Logging
  • 运行您的 java 示例
  • 将日志输出添加到您的帖子

  • 我认为启用日志记录就足够了,我希望在 Spring 中出现异常。但另外,测试是否执行了请求:
  • 设置代理,见 how-to-trace-soap-message-in-eclipse-ide - 不管是 REST 还是 SOAP,它是一个 TCP/IP 监视器
  • 运行你的 curl 示例
  • 运行您的 java 示例
  • 将这两个请求添加到您的帖子
  • 关于Spring RestTemplate 初学者 : The request sent by the client was syntactically incorrect (),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10247869/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com