【问题标题】:Request method 'PUT' not supported When calling from Resttemplate从 Resttemplate 调用时,不支持请求方法“PUT”
【发布时间】:2020-07-24 15:19:30
【问题描述】:

我必须使用 Resttemplate 调用 PUT 方法。我可以从 POST Man 获得服务。但是当我使用 Resttemplate 尝试来自 Java 的相同请求时,它会抛出错误。我在做什么可能是错误的。

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);

【问题讨论】:

标签: java rest resttemplate put


【解决方案1】:

如果你想在 PUT 请求的正文中发送changeRequestobject 数据,我建议你使用下一个 RestTemplate 交换方法调用:

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);

【讨论】:

    猜你喜欢
    • 2015-06-26
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    • 2016-05-24
    • 2013-03-19
    • 2020-08-31
    相关资源
    最近更新 更多