【问题标题】:Client Server Communication in REST: Using RestTemplate: Unable to send data to Server sideREST 中的客户端服务器通信:使用 RestTemplate:无法将数据发送到服务器端
【发布时间】:2013-08-07 09:20:33
【问题描述】:

我正在尝试在 REST、Spring 中设置客户端-服务器通信。

在客户端我有代码:

rresult = restTemplate.getForObject("http://localhost:8081/SpringMVCMerchant/movieTheater.htm", ResponseText.class, variable);

上面的变量是一个HashMap。我希望将此值变量传输到服务器端代码。我的服务器端代码是:

@ResponseBody
@RequestMapping(value="/movieTheater", method=RequestMethod.GET)
public ResponseText getCustomerInput(Map<String, Double> input) {
    Transaction transaction = new Transaction();
    ResponseText result = new ResponseText();
    if(transactionService.addTransaction(input))
        result.setMessage(ResponseStatus.SUCCESS.getStatus());
    else
        result.setMessage(ResponseStatus.FAILED.getStatus());
    return result;
}

在这方面,我期望 Map 输入将接收 Map 变量的值。但是,这并没有发生。我不想将值作为 url 参数发送。你能告诉我如何解决这个问题吗?

提前致谢!

【问题讨论】:

    标签: java rest spring-mvc client-server resttemplate


    【解决方案1】:

    您可以执行 HTTP POST 请求,而不是 HTTP Get 请求。

    见:https://stackoverflow.com/a/15944890/2179109

    【讨论】:

    • 感谢您的回复!我尝试使用 POST。我遇到了同样的 406 错误。
    猜你喜欢
    • 2023-03-08
    • 2017-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多