【发布时间】:2014-01-23 00:50:42
【问题描述】:
当向我的 Play 框架操作方法发出带有大主体的 POST 请求时,我在提取数据时得到 null。如果 body 很小,我可以很好地检索数据。
这是一个简短的数据集示例:
{
"creator": "zoltan",
"sport": "hike",
"geometry": [
{
"time": "2009-07-10 12:56:10 +0000",
"x": 10.275514,
"y": 47.514749,
"z": 756.587
},
{
"time": "2009-07-10 12:56:19 +0000",
"x": 10.275563,
"y": 47.514797,
"z": 757.417
}
]
}
当我在正文中使用此 JSON 发出 POST 请求时,一切正常。但是,如果我在 geometry 数组中添加更多 (~4000) 点,我会在操作中得到 null。
这是我的操作方法:
@Transactional
//@BodyParser.Of(Json.class) // tried with this as well
public static Result createTour() {
LOG.debug("Raw request body: " + request().body().asText());
JsonNode node = request().body().asJson();
LOG.debug("JSON request body: " + node);
TourDto tourDto;
try {
tourDto = jsonToTour(node);
int id = TourDataAccessUtils.create(tourDto);
return created(toJson(id));
} catch (JsonProcessingException e) {
LOG.error("While parsing JSON request.", e);
return Results.badRequest(
toJson(Throwables.getRootCause(e).getMessage()));
}
}
我尝试使用 chrome 中的 Advanced REST Client 和 ċurl 发送请求,均失败。
可能是什么问题?是不是我需要为大型请求包含一个 Content-Lenght 标头?如果是这样,我该如何手动计算任意 JSON 数据?
【问题讨论】:
标签: json playframework http-post playframework-2.2 http-content-length