I am trying to make a patch rest request to another API that accepts content type "application/json-patch+json". I am using Spring's webclient but I have not been able to get it to work. I keep getting "415 Unsupported media type"
I have tried the below;
WebClient webClient = WebClient.create(baseUrl);
Mono<ClientResponse> response = webClient.patch()
.uri(updateVmfExecutionApi, uuid)
.header("Content-Type", "application/json-patch+json")
.body(BodyInserters.fromFormData("lastKnownState", state))
.exchange();
I also tried:
WebClient webClient = WebClient.create(baseUrl);
Mono<ClientResponse> response = webClient.patch()
.uri(updateVmfExecutionApi, uuid)
.contentType(MediaType.valueOf("application/json-patch+json"))
.body(BodyInserters.fromFormData("lastKnownState", state))
.exchange();
For both cases I see the following error;
{"timestamp":"2020-09-17T20:50:40.818+0000","status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Unsupported Media Type","trace":"org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported\n\tat org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:215)\n\tat org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:421)\n\tat org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:367)\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.getHandlerInternal(RequestMappingHandlerMapping.java:449)
Seems it changes to 'application/x-www-form-urlencoded;charset=UTF-8' Is it even possible to use webclient for this content-type?
.bodyValue(state)
– Toerktumlare