我通过 cURL 将以下 json 发送到另一台服务器。
$postUrl = 'http://anotherserver.com/test.php';
$this->datatopost = array (
"rcpt_to" => $rcpt_to,
"to" => $to,
"subject" => $subject,
"header" => $headers,
"body" => $body,
);
$data = array (
'json' => json_encode($this->datatopost)
);
$bodyStr = http_build_query($data);
$postlength = strlen($data);
$ch = curl_init('www.xxx.com/test.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded',
'Content-Length: ' . strlen($bodyStr))
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
if(!curl_errno($ch))
{
$info = curl_getinfo($ch);
echo"<pre>"; print_r($info);
echo"</pre>";
}
并收到一条错误消息:
Request Entity Too Large
The requested resource
/test.php
does not allow request data with POST requests, or the amount of data provided in
the request exceeds the capacity limit.