简体   繁体   中英

PHP 413 (Request Entity Too Large)

When I'm trying to transfer a XML file to server I get this error.

In my scenario a web page processes a XML file with javascript and then upload the XML processed file to a PHP server.

The file capacity is 400K.

php.ini

post_max_size = 8M
upload_max_filesize = 2M
memory_limit = 128M

Client initial request:

$.ajax({
    type: "GET",
    url: "/dirname/filename.xml",
    dataType: "xml",
    async: false,
    success: function(data){
        xmlCID = data;
    },
    error: function(jqXHR, textStatus, errorThrown){
        console.log(jqXHR.responseText, textStatus, errorThrown);
        alert(textStatus);
    }
});

Client upload request

$.ajax({
    url: "/dirname/filename.xml",
    dataType: "xml",
    method: "PUT",
    processData: false,
    data: xmlCID,
    success: function(data){
        console.log(data);
    },
    error: function(jqXHR, textStatus, errorThrown){
       alert(jqXHR.responseText, textStatus, errorThrown);
    }
});

Unfortunely, server response is:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>413 - Request Entity Too Large</title>
 </head>
 <body>
  <h1>413 - Request Entity Too Large</h1>
 </body>
</html>

As hakre pointed out, beyond the settings in PHP you'll often receive 413 errors occur when the size of the request payload is beyond what the web server configuration allows. These directives vary by server, but here are some common ones (if you're using a hosted platform, you'll likely need to contact your host's support team):

If you're serving requests over HTTP and HTTPS, make sure that the relevant configuration applies to both.

While less common (more so in corporate networks), this can also have to do with other proxies or security devices that the request is being passed through, since each of those may have different limits affecting the handling of the request.

When in doubt, check the logs: first, make sure that the request is getting to your server (in the access logs), if it is, check the response code, and then also check the error logs.

Hope that helps!

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