$ resource PATCH请求返回HTTP 415

时间:2013-08-23 22:26:29

标签: spring-mvc angularjs

我定义了一个$ resource并添加了一个PATCH方法:

myapp.factory( 'Monitoring', function($resource) {
   return $resource('/webapp/network/v1/cronjobs/:id/:action', { id: '@id' }, {
       status: { method: 'PATCH', params:{id:"@id", action: 'status'}}
   }
   );
});

调用网址时,我得到PATCH http://localhost:8080/webapp/network/v1/cronjobs/1/status 415 (Unsupported Media Type)

    changeStatus: function(id, status) {
        var m = new Monitoring({id:id});
        m.status = status;
        m.$status();
    }

我的后端是春天

@RequestMapping(value = "/{id}/status", method = RequestMethod.PATCH)
public ResponseEntity<Void> patchStatus(@PathVariable("id") Long id,
        @RequestBody String status) {
}

1 个答案:

答案 0 :(得分:0)

我通过添加Content-Type标题来修复它:

status: { method: 'PATCH', headers:{'Content-Type': 'application/json'}, params:{id:"@id", action: 'status'}}

它有效,但这是正确的方法吗?