相关疑难解决方法(0)

通过JSON中的RestTemplate发出POST请求

我没有找到任何解决问题的例子,所以我想请你帮忙.我不能简单地使用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)

我的错是什么?

java rest spring json resttemplate

117
推荐指数
8
解决办法
31万
查看次数

将 JSON POST 请求从一个 REST API 转发到另一个

我有以下情况:

我的 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)

rest spring json spring-boot request-mapping

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

json ×2

rest ×2

spring ×2

java ×1

request-mapping ×1

resttemplate ×1

spring-boot ×1