首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在以curl格式传递POST数据时请求实体太大

在以curl格式传递POST数据时请求实体太大
EN

Stack Overflow用户
提问于 2019-03-23 05:49:19
回答 2查看 2.1K关注 0票数 2

我有一个fastcgi++服务。它通过POST接受4个参数,因为其中一个参数是密码。我的样本输入是61个字符。我就是这样称呼我的服务的:

代码语言:javascript
复制
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中,这是输出:

代码语言:javascript
复制
*   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:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-31 12:56:21

我应该说我使用的是fastcgi++库。正如@契诺者所提到的,413页不是apache的,而是fastcgi++。我应该先看医生的。它清楚地提到了这里,默认情况下没有启用POST。将构造函数添加到我的类并以我想要的POST请求的最大大小调用请求构造函数,解决了这个问题。

谢谢@汉舍里克,你为我做了这么多小时的调试。

票数 2
EN

Stack Overflow用户

发布于 2019-03-24 08:41:33

(不是回答,但太大了,不能发表评论)

如果运行这个php脚本,您会得到什么?

代码语言:javascript
复制
<?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";
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55311012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档