@Chesterfield25

Как принять и передать данные из post запроса?

На мой сервер приходит пост запрос как мне принять этот запрос а так же взять данные которые приходят и подставить их в значение

Значения которые нужно заменить
$data = array('api_key' => $row['api'] . "\t", 'amount' => $row['amount'] . "\t", 'to' => 'MDrZNBXHDeqjcircR7siunHwuzt4xgjCXw', 'currency' => $row['currency'] . "\t");


Полный код

require 'con.php';

$sql = 'SELECT currency, amount, api FROM post';
foreach ($condb->query($sql) as $row) {
    $row['amount'] . "\t";
    $row['currency'] . "\t";
    $row['api'] . "\t";
}

$url = 'https://site.com/';
$data = array('api_key' => $row['api'] . "\t", 'amount' => $row['amount'] . "\t", 'to' => 'MDrZNBXHDeqjcircR7siunHwuzt4xgjCXw', 'currency' => $row['currency'] . "\t");

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

var_dump($result);


У меня сработал данный код но правильное решение или же нет?

require 'con.php';

if (!empty($_POST["to"])) {

}
$sql = 'SELECT currency, amount, api FROM post';
foreach ($condb->query($sql) as $row) {
    $row['amount'] . "\t";
    $row['currency'] . "\t";
    $row['api'] . "\t";
}

$url = 'https://site.com/';
$data = array('api_key' => $row['api'] . "\t", 'amount' => $row['amount'] . "\t", 'to' => $_REQUEST['to'], 'currency' => $row['currency'] . "\t");

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

var_dump($result);
  • Вопрос задан
  • 266 просмотров
Решения вопроса 1
@66demon666
По навыкам джун - по факту безработный
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы