gpt4 book ai didi

json - 大体的 POST 请求在服务器端收到空

转载 作者:行者123 更新时间:2023-12-01 10:50:32 24 4
gpt4 key购买 nike

当向我的 Play 框架操作方法发出一个包含大量正文的 POST 请求时,我在提取数据时得到了 null。如果主体很小,我可以很好地检索数据。

这是一个示例短数据集:

{
"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 header ?如果是这样,我如何为任意 JSON 数据手动计算它?

最佳答案

请检查 PlayFramework documentation ,他们提到请求的默认最大长度为 100KB:

Max content length

Text based body parsers (such as text, json, xml orformUrlEncoded) use a max content length because they have to load allthe content into memory.

There is a default content length (the default is 100KB).

Tip: The default content size can be defined in application.conf:

parsers.text.maxLength=128K

You can also specify a maximum content length via the @BodyParser.Ofannotation:

// Accept only 10KB of data.
@BodyParser.Of(value = BodyParser.Text.class, maxLength = 10 * 1024)
pulic static Result index() {
if(request().body().isMaxSizeExceeded()) {
return badRequest("Too much data!");
} else {
ok("Got body: " + request().body().asText());
}
}

关于json - 大体的 POST 请求在服务器端收到空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20936046/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com