private static function httpPost($url, $data, $multipart_form_data = false)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
if ($multipart_form_data === true) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
} else {
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); // кодируется в виде application/x-www-form-urlencoded. Если без http_build_query, будет кодироваться как multipart/form-data
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if ($response === false) {
$error = curl_error($curl);
curl_close($curl);
return json_encode([
"error" => [
"code" => 400,
"message" => 'curl error: ' . $error
]
]);
}
curl_close($curl);
return $response;
}