0

I have to call a PUT method using Resttemplate. I am able to hit the service from POST Man. But when i try the same request from Java using Resttemplate its throwing error .What could be mistake i am doing.

405 : [{"category":"ACCESS","code":"METHOD_NOT_SUPPORTED","description":"Request method 'PUT' not 
supported","httpStatusCode":"405"}]

@Autowired
@Qualifier("orderMasterUpdateClient")
private RestTemplate orderMasterUpdateClient; // Loading the template with credentials and URL

ResponseEntity<SalesOrderDocument> responseEntity = orderMasterUpdateClient.exchange(
                URL,
                HttpMethod.PUT,
                new HttpEntity<>(headers),
                SalesOrderDocument.class, changeRequest);
VKP
  • 589
  • 1
  • 8
  • 34
  • 1
    Does this answer your question? [HTTP Status 405 - Request method 'PUT' not supported](https://stackoverflow.com/questions/35381402/http-status-405-request-method-put-not-supported) – varunkr Apr 11 '20 at 22:54
  • can you provide the request executed through Postman in curl command format? – Alcastic Apr 11 '20 at 23:53

1 Answers1

1

If you want to send changeRequestobject data in the body of the PUT request, I suggest you to use next RestTemplate exchange method call:

String url = "http://host/service";
ChangeRequest changeRequest = new ChangeRequest();
HttpHeaders httpHeaders = new HttpHeaders();
HttpEntity<ChangeRequest> httpEntity = new HttpEntity<>(changeRequest, httpHeaders);

ResponseEntity<ChangeRequest> response = restTemplate
            .exchange(url, HttpMethod.PUT, httpEntity, ChangeRequest.class);
Alcastic
  • 374
  • 5
  • 15