postForObject方法调用错误,报400 bad request

纵一苇就是我 2017-08-10 11:34:08
我在自己的程序中调用别人的服务中restful api,调用方式的POST,用了rRestTemplate的postForObject方法,但是总是报

POST request for "http://192.168.1.91:8030/moc/task/distribute" resulted in 400 (Bad Request); invoking error handler

2017-08-10 11:23:38.169 ERROR 18144 ---
[nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] :
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
[Request processing failed; nested exception is org.springframework.web.client.HttpClientErrorException: 400 Bad Request] with root cause
org.springframework.web.client.HttpClientErrorException: 400 Bad Request

我的调用代码片段如下,请大家帮忙看看:

//MOC接口的地址http://{domain}:{port}/moc/task/distribute
String mocTaskDistributeUrl = "http://192.168.1.91:8030/moc/task/distribute";
DeliverChangeParameter[] deliveringChanges = getRequestBody(deliveringChangeId, deliveringHostIp);

//接收MOC的返回消息

//为rest请求准备请求体
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<DeliverChangeParameter[]> httpEntity = new HttpEntity<DeliverChangeParameter[]>(deliveringChanges);

//发送请求
UpdateResult updateResult = new UpdateResult();
updateResult = restTemplate.postForObject(mocTaskDistributeUrl, httpEntity, UpdateResult.class);
...全文
2203 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧