【发布时间】:2016-11-17 06:22:40
【问题描述】:
我想将以下(工作)curl sn-p 转换为 RestTemplate 调用:
curl -i -X POST -d "email=first.last@example.com" https://app.example.com/hr/email
如何正确传递 email 参数?以下代码导致 404 Not Found 响应:
String url = "https://app.example.com/hr/email";
Map<String, String> params = new HashMap<String, String>();
params.put("email", "first.last@example.com");
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.postForEntity( url, params, String.class );
我尝试在 PostMan 中制定正确的调用,我可以通过将电子邮件参数指定为正文中的“表单数据”参数来使其正常工作。在 RestTemplate 中实现此功能的正确方法是什么?
【问题讨论】:
-
试试restTemplate.exchange();
-
您在此处提供的 url 可接受的内容类型是什么?
-
看看这个博客,我猜它正在尝试做同样的事情techie-mixture.blogspot.com/2016/07/…
-
@TharsanSivakumar 该网址将返回 JSON。
标签: java spring rest resttemplate