413 Full HEAD error

14,176

Don't use HEAD or GET for large parameters. Those should only be used for idempotent requests(repeating it doesn't break anything), and requests that only retrieve data(i.e. searching or filtering a product database) anyway.

Use a POST request instead:

<script>
    $(function(){
        $('.publish').click(function(){
            title = $('#title').val();
            description = $('#description').val();
            article = $('#article').val();

            $.ajax({
                type:       "post",
                url:        "/articles",
                data:       {action:'add', title:title, description:description, article:article},
                // .... skipped unchanged lines
    </script>

This is a one-line change.

On the server, make sure you use doPost() instead of doGet() in the servlet. You can get parameters in a similar fashion.

Share:
14,176
leo
Author by

leo

By day: Computer science student By night: Coder, hacker, beer drinker, binge watcher

Updated on June 15, 2022

Comments

  • leo
    leo almost 2 years

    i have made a dynamic blog engine, where multiple authors can publish articles.

    the author goes to a page where he inputs the 'article' 'description' and 'the whole article' in three <textarea> Then i store all the values in 3 variables and store it in the database via an ajax based request.

    The Problem: The HttpServerRequest is too large and it gives a 413 FULL Head error, and the request doesnt get through.

    The Code:

    The HTML:

    <div class="container">
            <h4 class="text-left">Title:</h4>
            <textarea id="title" rows="2" cols="" ></textarea>
            <br />
            <h4 class="text-left">Description:</h4>
            <textarea id="description" rows="5" cols="" ></textarea>
            <br />
            <h4 class="text-left">Article:</h4>
            <textarea id="article" rows="40" cols="" onkeyup="replaceWordChars(this.value)"></textarea>
            <br />
    
            <div class="publish btn">Publish</div>
            <br />
            <br />
        </div>
    

    The Script:

    <script>
        $(function(){
            $('.publish').click(function(){
                title = $('#title').val();
                description = $('#description').val();
                article = $('#article').val();
    
                $.ajax({
                    type:       "get",
                    url:        "/articles",
                    data:       {action:'add', title:title, description:description, article:article},
                    success:    function(code)
                    {
                                alert("published"); 
                                window.location="dashboard.jsp";
                    }
    
                }).error(function(){ alert("error"); })
                .complete(function(){ alert("complete"); });
    
            });
    
        });
        </script>
    

    The ERROR:

    "NetworkError: 413 FULL head - http:///articles?action=add&title=blah&..........gs.%0A%0A&userId=1"

    The Question:

    Is there an alternate way to send a big server request?? I also read on google that we can change the size, to match huge requests?

    Answers are preferred in java, HTML, javascript (or) jQuery

    EDIT I read here that we can set the size limit of post request in header? How can i do it in GAE?