ERROR:
Request Entity Too Large The requested resource /check.php does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit.
Whar could be the reason for this error? I think data size cannot be the reason and I know ./check.php accepts P开发者_运维技巧OST method. Is it like some security that is lmiting access?
regards, aqif
If you really want to use POST then you will have use CURLOPT_POST and CURLOPT_POSTFIELDS in this order. Having the result is handy for debugging as well.
<?php
$params=array(
'a'=>'text1',
'b'=>'text2'
);
$curl=curl_init();
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($curl);
print $result;
edit: just a note, if you want to send no parameters with the post, use an empty array. empty string will break curl.
Not sure if this will help anyone, but the following is what solved the issue for me:
I had the following:
$ch = curl_init($process_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$results = @curl_exec($ch);
the CURLOPT_POST is what was causing the problem. My actual curl didn't contain any $_POST vars, it only had a $_GET query string. Once I removed the line with CURLOPT_POST, everything worked as expected.
I did not experience this issue on a CentOS install, however, I did on my Mac using OSX Lion with PHP 5.3+
If you are forced to make a POST request without parameters, you can set them to empty string or array. That solved this issue for me.
Either
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
Or
curl_setopt($ch, CURLOPT_POSTFIELDS, array());
Be aware that the latter of these resets the content-type header implicitly.
I ran into a similar problem with WFetch. I was specifying the Content-Length header myself, and it turns out that WFetch was tacking on its own Content-Length header. After removing my Content-Length header, everything worked. Could this be the case with Curl, too?
Well, that error response is definitely not intended a security measure. RFC 2616 says this about 413 Request Entity Too Large
:
The server is refusing to process a request because the request entity is larger than the server is willing or able to process. The server MAY close the connection to prevent the client from continuing the request.
Did you verify that the size is not the problem? Many webhosts have a rather small POST upload limit (there are few things which would throw a 413).
Otherwise, it could be the PHP script itself returning this response (via header()
).
If you use curl_exec that you must set
curl_setopt($ch, CURLOPT_POSTFIELDS, **array()**);
If you'll miss that, so you'll have Error 413 Request Entity Too Large
精彩评论