【问题标题】:How to configure rest template in Spring MVC 4?如何在 Spring MVC 4 中配置 rest 模板?
【发布时间】:2014-11-08 00:51:43
【问题描述】:

如何在 Spring MVC 4 中使用命名空间配置/xml 配置和基本 http 主机配置 RestTemplate。

【问题讨论】:

  • 你试过documentation吗?你的问题太笼统了。
  • @Jeyp,是的,我已经做到了。寻找使用 http 主机的东西,所以我不会配置 web 服务的方案、url 和主机
  • 你想做什么?您想执行 HTTP POST 请求吗?或者您想构建一个接受 HTTP POST 的 Web 应用程序?
  • 我想发送http post和http get到服务器
  • 我发布了一个使用 RestTemplate 的请求示例。

标签: java spring rest resttemplate


【解决方案1】:

使用 RestTemplate 类非常容易。 Here 是一个很好的概述。

RestTemplate rest = new RestTemplate();
String response;

response = rest.getForObject("http://www.google.com", String.class);

Object postData = null;
response = rest.postForObject("http://yourdomain.com/example", postData, String.class);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-19
  • 1970-01-01
  • 2019-03-01
相关资源
最近更新 更多