Android用Spring RestTemplateクラスを使用してオブジェクトを送信しています。それは有効な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サポートされていないメディアタイプのエラーが発生してサーバーが復帰しました。
は、念のために、ここにあります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