最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - PHP 413 (Request Entity Too Large) - Stack Overflow

programmeradmin4浏览0评论

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="" xml:lang="en" lang="en">
 <head>
  <title>413 - Request Entity Too Large</title>
 </head>
 <body>
  <h1>413 - Request Entity Too Large</h1>
 </body>
</html>

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/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>
Share Improve this question asked Jul 15, 2015 at 10:56 pepperavpepperav 5371 gold badge6 silver badges16 bronze badges 4
  • Since it's 40 minutes after you asked the question and there are no takers, I'm gonna ask a (perhaps) stupid question. Did you restart the web server after modifying php.ini? Check with phpinfo(). – unfairhistogram Commented Jul 15, 2015 at 11:38
  • Yes, sure. I've just checked by phpinfo(). – pepperav Commented Jul 15, 2015 at 12:07
  • 2 The error message most likely is from your web-server (not PHP). That means you have to check the error-log of your web-server and see what is causing the issue. You should find it in there with a more specific technical description what caused the error. – hakre Commented Jul 15, 2015 at 18:04
  • Yes, problem was into webserver config file. I use lighttpd and upload directory was missing. – pepperav Commented Jul 16, 2015 at 8:16
Add a ment  | 

1 Answer 1

Reset to default 4

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 mon ones (if you're using a hosted platform, you'll likely need to contact your host's support team):

  • Nginx: Look at the client_max_body_size directive for nginx.conf (http://nginx/en/docs/http/ngx_http_core_module.html#client_max_body_size)

  • Apache: The directive LimitRequestBody can be used in httpd.conf or in directory-level .htaccess files (http://httpd.apache/docs/2.4/mod/core.html#limitrequestbody)

  • IIS: Look into maxAllowedContentLength (part of requestFiltering > requestLimits), or UploadReadAheadSize in IIS6 (IIS solutions are very version-dependent, so I'd remend researching a bit).

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

While less mon (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!

发布评论

评论列表(0)

  1. 暂无评论