c++curl返回413请求实体过大,但是post大小远小于max大小

c++ curl returns 413 request entity too large however the post size is much less than max size

本文关键字:post 小于 大小 max 但是 返回 请求 实体 c++curl      更新时间:2023-10-16

我注意到我的一些帖子没有提交,所以我在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');

我得到了:2000万

然后从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距离2000万还很远

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

这个问题既不在C++中,也不在PHP中。

如果PHP前面有一些服务器(通常是用于unix风格服务器的nginxapache,或者用于windows服务器的microsoft的IIS,尽管也存在其他服务器(,那么问题几乎肯定是该服务器中的配置选项。

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

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