解决netty作为web,post请求体过大导致413 Request Entity Too Largew问题

问题

项目中使用netty作为web服务,postman请求体内容超出5mb请求netty时,返回413 Request Entity Too Large

解决

查询了一下资料:https://netty.io/4.0/api/io/netty/handler/codec/http/HttpObjectAggregator.html

  ChannelPipeline p = ...;
  ...
  p.addLast("decoder", new HttpRequestDecoder());
  p.addLast("encoder", new HttpResponseEncoder());
  p.addLast("aggregator", new HttpObjectAggregator(1048576));
  ...
  p.addLast("handler", new HttpRequestHandler());

修改HttpObjectAggregator的值 例如允许100MB那就是

  p.addLast("aggregator", new HttpObjectAggregator(100 * 1024 * 1024));

你可能感兴趣的:(1024程序员节)