java post 500_java - Spring RestTemplate Post获得500内部服务器错误 - 堆栈内存溢出

嗨,我是Spring Framework的新手,我已经编写了应用程序,该应用程序使用Resttemplate将对象发布到RESTAPI,但出现此错误

23:07:05.856 [main] DEBUG o.s.web.client.RestTemplate - Created POST request for

"http://dummyurl.net/Index"

23:07:05.887 [main] DEBUG o.s.web.client.RestTemplate - Setting request Accept

header to [application/json, application/*+json]

23:07:05.887 [main] DEBUG o.s.web.client.RestTemplate - Writing

[org.hrishi.ConsumeReStApi.Info@727803de] as "application/json" using

[org.springframework.http.converter.json.MappingJacksonHttpMessageConverter@704921a5]

23:07:05.981 [main] WARN o.s.web.client.RestTemplate - POST request for "dummyurl.net"

resulted in 500 (Internal Server Error); invoking error handler

Exception in thread "main" org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error

at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:94)

at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:598)

at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:556)

at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:512)

at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:363)

at org.hrishi.ConsumeReStApi.App.main(App.java:35)

这是我的代码

String url= "http://dummyurl.net/Index";

RestTemplate restTemplate = new RestTemplate();

MultiValueMap headers = new LinkedMultiValueMap();

headers.add("Content-Type", "application/json");

Info info1=new Info();

info1.Id="1711";

info1.Name="Hrishi";

HttpEntity HReq=new HttpEntity(info1,headers);

ResponseEntity info = restTemplate.postForEntity(url, HReq, Info.class);

System.out.print("id : "+info.getBody());

这是请求对象

public class Info {

public String Id;

public String Name;

public String getName() {

return Name;

}

public String getId() {

return Id;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值