apache - 在curl中传递POST数据时请求实体太大

标签 apache curl http-status-code-413 fastcgi++ fedora-29

我有一个 fastcgi++ 服务。 POST 需要 4 个参数,因为其中之一是密码。我的示例输入是 61 个字符。这就是我调用我的服务的方式:

curl --data 'name=test&address=abc&phoneNumber=0987654321&password=test123' http://localhost/cgi-bin/add-user.fcg

我收到此错误:413 请求实体太大。根据我的研究,我发现这意味着 apache 期望的 body 比实际的要小。因此,我将 LimitRequestBody 0 添加到 httpd.conf (我不在生产环境中)。但apache仍然提示请求实体太大。

我向curl 添加了-v,这是输出:

*   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

最佳答案

我应该提到我正在使用 fastcgi++ 库。如@covener前面提到,413 页面不是 apache 的。原来是fastcgi++。我应该先阅读文档。它清楚地提到here默认情况下不启用 POST。在我的类中添加一个构造函数并使用我想要的 POST 请求的最大大小调用 Request 构造函数,解决了问题。

附注非常感谢@hansherik感谢您为我完成的所有调试时间。

关于apache - 在curl中传递POST数据时请求实体太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55311012/

相关文章:

PHP Post 变量有重复的、已修改的数据

apache - htaccess 密码保护但不在本地主机上

php - 带有证书的curl命令到php SoapClient (BankID)

AngularJS 在 Loopback API 中获取 413(请求实体太大)的状态代码 0

css - 从服务器请求图像时 403 Forbidden

java - Tomcat 8 Embedded - ContextResource 已弃用的替代方案

docker - 如何使用 Docker 注册表 API 提取有关容器的信息?未经授权

string - Windows curl 字符串格式化

python - Flask 文件上传限制

Django nginx 413请求实体太大