@requestbody @responsebody返回http 400

时间:2014-03-03 18:23:39

标签: java spring

这是我的控制器

@RequestMapping(value = "/ping", method = RequestMethod.POST)
public @ResponseBody PingResponse ping(@RequestBody PingRequest request){
    try {
        Thread.sleep(request.delay);
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    PingResponse res = new PingResponse();
    res.setTimeStamp(request.getTimeStamp());

    return res;
}

这是pojos

class PingRequest {
    private long delay;
    private long timeStamp;
    public long getDelay() {
        return delay;
    }
    public void setDelay(long delay) {
        this.delay = delay;
    }
    public long getTimeStamp() {
        return timeStamp;
    }
    public void setTimeStamp(long timeStamp) {
        this.timeStamp = timeStamp;
    }

}

class PingResponse {
    private long timeStamp;

    public long getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(long timeStamp) {
        this.timeStamp = timeStamp;
    }

}

Http Request

POST http://localhost:9000/myapp/ping HTTP/1.1
Host: localhost:9000
Content-Length: 41
Content-Type: application/json

{"timeStamp":1393860018158,"delay":1000 }

Http回复

HTTP/1.1 400 Bad Request

为什么我会收到Http 400?

0 个答案:

没有答案