0

I'm passing an int array of about 1500 integers from my react front-end to my Spring boot back-end using an axios post call.

When the call is made, I get this error:
java.lang.IllegalArgumentException: Request header is too large.

I genuinely don't know what the issue is or how to resolve it. All I want to do is retrieve this list of numbers from the front-end and iterate through them & print them on the back-end (for now). If you know an easier way to do so, feel free to enlighten me.

Thank you

Here's my front-end code: enter image description here



Here's my back-end code: enter image description here

coder_coder123
  • 101
  • 2
  • 3
  • 9

3 Answers3

1

you should override the default max-http-header-size in your application.properties or your application.yml file.

the default value for max http header for the embedded tomcat is 8kb.

just paste this to your application.properties file in the back end server:

server.max-http-header-size=50000

this will override the default 8kb allowed header to maximum of 50kb. additionally please check what your http header request includes in the server side.

Dev93
  • 93
  • 2
  • 13
0

Theoretically your solution does work as the RFCs describing the URI and query string imposes no limit. Unfortunately this is not how it was implemented.

Either the client or the server can impose a limit. There is a good SO answer regarding the client's limits. I am not familiar with react's limit as I am mostly focused on backend, you have to research that yourself. As you use Spring there are two usual server: Tomcat and Netty. Both of them limits the length of the url. Tomcat limits at 8K, Netty at 4K. The list of 1500 integers can be more than those limits.

You have to set a new limit for the backend (for Tomcat the link describes that, for Netty I have never tried that) and hope that the frontend won't expose any limit.

OR... You can use the @RequestBody and add that information to the body.

Example (source):

@PostMapping("/request")
    public ResponseEntity postController(
      @RequestBody LoginForm loginForm) {
curl -i \
    -H "Accept: application/json" \
    -H "Content-Type:application/json" \
    -X POST --data 
      '{"username": "johnny", "password": "password"}' "https://localhost:8080/.../request"

I would use the @RequestBody instead of the query parameters as it is designed for such data.

Gebezs
  • 696
  • 3
  • 9
0

In theory there is no limit to header length. But, it is logical for web servers to have a limit. I believe that you are using tomcat for your back-end service.

Tomcat the default value is 4k. There are mainly two ways of getting over with this error :

  1. To configure tomcat to accept more(new limit): <Connector port="8080" maxHttpHeaderSize="65536" protocol="HTTP/1.1" ... />
  2. Or add server.max-http-header-size=65536

Check this link too: https://thewebspark.com/2017/12/06/tomcat-request-header-too-large-resolved/

Note: Imho, it is better to use the body for such sized input instead of tuning a server or adding an extra property for just this.

Aman
  • 1,627
  • 13
  • 19