Android RestTemplate 클래스 용 Spring을 사용하여 객체를 보내고 있습니다. 유효한 JSON (모든 방식으로 확인했습니다)을 보내고 http 헤더와 내용 유형이 올바른 것입니다.서버가 명백한 이유없이 415 HTTP 코드를 반환합니다.
try {
Event event = new Event();
// Set event parameters.
RestTemplate restTemplate = new RestTemplate();
String url = Const.ADD_EVENT_REQUEST + Const.getRequiredRequestParameters(app);
return restTemplate.postForObject(url, event, Boolean.class);
} catch (Exception e) {
Log.e("Add event task", e.getMessage(), e);
return false;
}
서버에서 개체를 받기 : :이 "절약 이벤트"로그가 인쇄되지 않습니다
@RequestMapping(value = "/add", method = RequestMethod.POST)
public @ResponseBody Boolean createEvent(@RequestBody Event event) {
try {
Logger.getLogger(EventRestAction.class).info("saving event " + event);
eService.save(event);
return true;
} catch (Exception e) {
Logger.getLogger(EventRestAction.class)
.error(e.getMessage(), e);
return false;
}
}
객체를 보내기. 415 Unsupported media type error (지원되지 않는 미디어 유형 오류)와 함께 서버가 반환됩니다.
그냥 경우에는 여기 년대 dispatcher-servlet.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<context:component-scan base-package="ee.lapikud.ttyapp" />
<mvc:annotation-driven />
<mvc:interceptors>
<bean class="ee.lapikud.ttyapp.interceptor.RequestSecurityInterceptor" />
</mvc:interceptors>
</beans>
문제는 매우 광범위하지만 꽤 붙어있어 - 어떤이의 원인이 될 수 있을까?
사용하는 스프링의 버전? 3.0.5-RELEASE로 다운 그레이드하여 해결 한 유사한 문제에 대해 고심했습니다. 최신 버전에는 약간의 결함이 있습니다. –
죄송합니다. 1 년 넘게 그 프로젝트를 해왔습니다. 많은 것을 기억하지 못하여 더 이상 세부 사항을 제공 할 수 없습니다. 나는 이것이 결코 해결되지 않았을 것이라고 확신한다. – j0ntech