헤더가있는 GET 요청을 보내야합니다 : Content-Type: application/camiant-msr-v2.0+xml
. 나는 서버로부터 XML 응답을 기대한다. 나는 우편 배달부와 요청 및 응답을 테스트하고 모든 것이 좋습니다. 그러나 봄에 RestTemplate
으로하려고하면 항상 400 개의 잘못된 요청을받습니다. spring
에서 예외는 다음과 같습니다맞춤 헤더로 Resttemplate GET 요청
Jul 09, 2016 12:53:38 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [/smp] threw exception [Request processing failed; nested exception is org.springframework.web.client.HttpClientErrorException: 400 Bad Request] with root cause
org.springframework.web.client.HttpClientErrorException: 400 Bad Request
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:641)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475)
내 코드 :
MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
headers.add("Content-Type", "application/camiant-msr-v2.0+xml");
HttpEntity<?> entity = new HttpEntity<Object>(headers);
log.debug("request headers: " + entity.getHeaders());
ResponseEntity<String> response = restTemplate.exchange(queryUrl, HttpMethod.GET, entity, String.class);
디버그 메시지가 올 것으로 보인다 {Content-Type=[application/camiant-msr-v2.0+xml]}
로 헤더를 보여줍니다. 내 요청에 어떤 문제가 있는지, 디버깅 할 수있는 요청을 볼 수있는 방법이 있는지 궁금합니다.
GET을 보내는 경우 왜 'Content-Type' 헤더를 제공합니까? 대신에 '수락'을 원하십니까? –
@ nicholas.hauschild 서버는 헤더를 제공함으로써 만 XML 응답을 얻을 수 있다고 기대하기 때문에. –
@ nicholas.hauschild 나는 당신이 무슨 뜻인지 좀 이해하지만, API 스펙에 의하면, 또한 Postman이 잘 작동한다고 나와있다. –