【发布时间】:2015-07-30 07:41:23
【问题描述】:
我需要帮助创建对我的 Java Spring Restcontroller 的 POST 请求。
这是我的控制器 -
@RestController
@RequestMapping("hedgesimulator/")
public class HedgeSimulatorController {
@RequestMapping(value = "hedgesim/", method = RequestMethod.POST)
@ResponseBody
public HedgeSimulatorLog putHedgeSimulation(
@RequestBody HedgeSimulatorLog hedgeSimulatorLog) {
System.out.println(hedgeSimulatorLog.toJsonString());
return hedgeSimulatorLog;
}
}
我正在使用 Chrome 的“Advanced Rest Client”插件将我的请求发布到我的 URL(我确定我的 localhost 运行正常,等等)
我需要在标题中添加什么?
我收到“HTTP 400 - 状态报告:客户端发送的请求在语法上不正确”的错误
请帮忙!
【问题讨论】:
-
您可能希望将 Spring MVC 日志记录级别设置为 DEBUG,并检查您的服务器访问日志以获取有关正在发出的请求的更多信息。听起来请求是错误的 - 也可以尝试使用 curl 或其他命令行工具发出请求。最后,我认为
@ResponseBody在@RestController中是多余的。 -
我认为请求有效负载无法转换为 HedgeSimulatorLog bean。您可以发布 HedgeSimulatorLog bean 和示例 JSON 有效负载吗?
标签: java spring post http-status-code-400