Слишком большой объект запроса при передаче данных POST в curl
У меня есть сервис fastcgi++. Он принимает 4 параметра через POST, потому что один из них является паролем. Мой пример ввода составляет 61 символов. Вот как я называю свою службу:
curl --data 'name=test&address=abc&phoneNumber=0987654321&password=test123' http://localhost/cgi-bin/add-user.fcg
Я получаю эту ошибку: 413 Запрос сущности слишком велик. Основываясь на своих исследованиях, я обнаружил, что это означает, что apache ожидал меньшего тела, чем получил. Итак, я добавил LimitRequestBody 0
на httpd.conf (я не в производственной среде). Но apache все еще жалуется, что объект запроса слишком велик.
Я добавил -v к curl, и это вывод:
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 80 (#0)
> POST /cgi-bin/add-user.fcg HTTP/1.1
> Host: localhost
> User-Agent: curl/7.61.1
> Accept: */*
> Content-Length: 60
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 60 out of 60 bytes
< HTTP/1.1 413 Request Entity Too Large
< Date: Sun, 24 Mar 2019 03:48:09 GMT
< Server: Apache/2.4.38 (Fedora) mod_fcgid/2.3.9
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8
<
* Closing connection 0
<!DOCTYPE html><html lang='en'><head><title>413 Request Entity Too Large</title></head><body><h1>413 Request Entity Too Large</h1></body></html>
Это мой httpd.conf:
ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI
Require all granted
SetHandler fcgid-script
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
#I added the line below
LimitRequestBody 0
Это fcgid.conf:
AddHandler fcgid-script fcg fcgi fpl
Sane place to put sockets and shared memory file
FcgidIPCDir /run/mod_fcgid
FcgidProcessTableFile /run/mod_fcgid/fcgid_shm
2 ответа
Я должен был упомянуть, что я использовал библиотеку fastcgi++. Как упомянул @ covener, страница 413 не была страницей Apache. Оказывается, это был fastcgi++. Я должен был прочитать документы в первую очередь. Здесь ясно упоминается, что POST не включен по умолчанию. Добавление конструктора в мой класс и вызов конструктора Request с максимальным размером POST-запросов, который я хотел, решили проблему.
PS hanshenrik спасибо @ hanshenrik за все часы отладки, которые вы сделали для меня.
(не ответ, но слишком большой для комментария)
что вы получите, если запустите этот скрипт php?
<?php
declare(strict_types=1);
header("Content-Type: text/plain;charset=utf-8");
$ch=curl_init('http://localhost/cgi-bin/add-user.fcg');
curl_setopt_array($ch,array(CURLOPT_USERAGENT=>'curl/7.61.1',CURLOPT_RETURNTRANSFER=>1));
$post_str="";
for($i=0;$i<61;++$i){
curl_setopt_array($ch,array(
CURLOPT_POST=>1,
CURLOPT_POSTFIELDS=>$post_str,
));
curl_exec($ch);
$code=curl_getinfo($ch,CURLINFO_RESPONSE_CODE);
echo "bytes: {$i} code: {$code}\n";
$post_str.="a";
}
curl_close($ch);
echo "finished loop";