我没有找到任何解决问题的例子,所以我想请你帮忙.我不能简单地使用JSON中的RestTemplate对象发送POST请求
每次我得到:
org.springframework.web.client.HttpClientErrorException:415不支持的媒体类型
我以这种方式使用RestTemplate:
...
restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> list = new ArrayList<HttpMessageConverter<?>>();
list.add(new MappingJacksonHttpMessageConverter());
restTemplate.setMessageConverters(list);
...
Payment payment= new Payment("Aa4bhs");
Payment res = restTemplate.postForObject("http://localhost:8080/aurest/rest/payment", payment, Payment.class);
Run Code Online (Sandbox Code Playgroud)
我的错是什么?
我有以下情况:
我的 REST API 一:
@RestController
@RequestMapping("/controller1")
Public Class Controller1{
@RequestMapping(method = RequestMethod.POST)
public void process(@RequestBody String jsonString) throws InterruptedException, ExecutionException
{
............
}
}
Run Code Online (Sandbox Code Playgroud)
REST API(Controller1) 的 JSON POST 请求 request1:
{
"key1":"value1",
"key2":"value2"
}
Run Code Online (Sandbox Code Playgroud)
我的 REST API 两个:
@RestController
@RequestMapping("/controller2")
Public Class Controller2{
@RequestMapping(method = RequestMethod.POST)
public void process(@RequestBody String jsonString) throws InterruptedException, ExecutionException
{
............
}
}
Run Code Online (Sandbox Code Playgroud)
REST API(Controller2) 的 JSON 请求 request2:
{
"key1":"value1",
"key2":"value2",
"key3":"value3"
}
Run Code Online (Sandbox Code Playgroud)
我有几个这样的“原始”请求。现在,我期待一个 JSON 请求,我们称之为 request3,它是这种“原始”查询的组合 - 如下所示:
{
{
"requestType":"requestType1", …Run Code Online (Sandbox Code Playgroud)