简体   繁体   中英

Post large JSON object using ajax request

I need help with posting large JSON object to server using ajax in angularjs. When I send JSON object with around 10000 records in an ArrayList using post request,It gets accepted and I get the response for the same.But when I upload 30000 records or more and try to send it using ajax, it returns following error :-

[io.undertow.request] (default task-5) UT005007: Request was not fully consumed

How can I fix this?

I am using Wildfly 10 and java 8. Is there any post size parameter I can increase?

You seem to be usingUndertow for receiving the POST request. Check what is the value of the MAX_ENTITY_SIZE option in your setup, perhaps it was limited:

The default maximum size of a request entity. If entity body is larger than this limit then a java.io.IOException will be thrown at some point when reading the request (on the first read for fixed length requests, when too much data has been read for chunked requests). This value is only the default size, it is possible for a handler to override this for an individual request by calling io.undertow.server.HttpServerExchange.setMaxEntitySize(long size) . Defaults to unlimited.

As suggested in this thread this is potentially configured in Spring using MultipartConfigFactory bean:

@Bean
public MultipartConfigElement multipartConfigElement() {
     MultipartConfigFactory factory = new MultipartConfigFactory();
     factory.setMaxFileSize("100MB");
     factory.setMaxRequestSize("100MB");
     return factory.createMultipartConfig();
}

The suggestion @KarolDowbecki made will likely work but there is another way too. In the standalone.xml file you're using, you can change from:

<http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>

to:

<http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true" max-post-size="16777216"/>

to increase, in this case, to 16MB. The default is 10MB on at least Wildfly 16.

Alternatively, if you want to script this so that you don't have to manually modify standalone.xml you can use the jboss-cli and run:

/subsystem=undertow/server=default-server/http-listener=default/:write-attribute(name=max-post-size,value=16777216)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM