【问题标题】:c++ curl returns 413 request entity too large however the post size is much less than max sizec ++ curl返回413请求实体太大但是帖子大小远小于最大大小
【发布时间】:2018-07-29 09:06:22
【问题描述】:

我注意到我的一些帖子没有提交,所以我在 c++ 代码中看到了 curl 的输出,它给出了

  <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
  <html><head>
  <title>413 Request Entity Too Large</title>
  </head><body>
  <h1>Request Entity Too Large</h1>
  The requested resource<br />/receiver.php<br />
  does not allow request data with POST requests, or the amount of data provided in
  the request exceeds the capacity limit.
  </body></html>

我用这个测试了 php 端发布请求的最大大小:

echo ini_get('post_max_size');

我得到了:20M

然后得到从 c++ 代码发送的帖子的大小,如下所示:

void send_request(string url, string field,string data) {
string post_req = field + "=" + data;
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_req.c_str());
cout << "post size : " << post_req.size() << endl;
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}

帖子只有 1059544 字节 = 1M 距离20M还很远

php 方面的问题在哪里?还是c++代码?

【问题讨论】:

  • 为什么投反对票?
  • 您使用的是哪个网络服务器?它的请求大小限制是多少?你的php代码在哪里?我们需要一个minimal reproducible example
  • 正如我所说,我在 php 端打印了 post_max_size 值,它给了我 20M,我的 php 是免费的奖励空间托管。我搜索了他们的请求大小限制,但没有找到任何东西,我可能会联系支持,因为 php 结果可能是错误的
  • post_max_size 是 php 将接受的最大 post 请求大小,如果不是更多,您的应用程序和 php 之间将至少有一个 Web 服务器,这将有自己的规则
  • 我现在提交了一张票,等待他们的回复,我认为你是对的,我必须购买一个付费帐户

标签: php c++ curl


【解决方案1】:

问题既不是 C++ 也不是 PHP。

你在 PHP 前面有一些服务器(通常是 nginxapache 用于 unix 风格的服务器,或者微软的 IIS 用于 windows-servers,尽管其他服务器也存在),问题几乎可以肯定是配置该服务器中的选项。

不太常见的是,您的服务器也可能有防火墙生成该响应,但更可能是某些服务器软件,如上所述。

同样,不相关,但是您的 c++ 代码中有一个错误:数据和字段都应该是 url 编码的,但显然不是。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-30
    • 2014-12-23
    • 1970-01-01
    • 2012-09-23
    • 2015-10-04
    • 2015-01-25
    • 2014-12-04
    相关资源
    最近更新 更多