1

я делаю API запрос, но в ответ получаю ошибку:

{"success":"false","error":"Invalid JSON data in request body: Syntax error.","code":0,"status":400}

Код запроса:

$data = array(
    'merchantUuid' => "$merchantUuid",
    'orderId' => "$orderId",
    'amount' => "$amount",
    'currency' => "$currency",
    'ip' => "$ip",
    'userAgent' => "$userAgent",
    'urlSuccess' => "$urlSuccess",
    'urlFail' => "$urlFail",
    'urlResult' => "$urlResult"
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.alikassa.com/v1/site/deposit");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type: application/json"
));

$response = curl_exec($ch);
curl_close($ch);
0

1 ответ 1

1

Явно преобразовать в json:

$postdata = json_encode($data);

https://stackoverflow.com/questions/11079135/how-to-post-json-data-with-php-curl

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.