私は少し見回しましたが、私の問題を解決する解決策が見つかりません。次のエラーが表示されます:「要求された URL がエラーを返しました: 413。」
HTTPS 経由で URL に curl と PHP 経由でいくつかの情報を投稿しています。宛先は http ではなく https であるため、リクエストとともに「Content-Length」を渡す必要があると言われました。
私が使用しているコードは次のとおりです。
$user = '11111111111111111';
$books = array(111);
$data = array("action" => "books-shared", "userID" => $user, "bookIDs" => $books);
$data_string = array('json'=>json_encode($data));
$target_url = 'https://www.test.com/test.php'; // fake URL of course
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$api = curl_exec($ch);
私の strlen($data_string) コマンドは値 5 を返しています。これは、$data_string の実際の長さよりもはるかに長い値です。他の何かが原因である可能性があると誰かが考えない限り、これが問題だと思います。