5
I have a question about the implementation of a web service, look at the logic:
I have a process that searches the data of several users in a system (system A), and I want to take this data and send to another system (system B), in both cases the systems are written in PHP.
This way I have the following script to fetch the user data from system A
export.php file
<?php
//busca os dados do banco do sistema A
$r = mysqli_fetch_array($q);
//API Url
$url = 'migracao/import_usuario.php';
//Initiate cURL.
$ch = curl_init($url);
$jsonData = json_encode($r);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData );
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($jsonData ))
);
$result = curl_exec($ch);
In my other file, already in system B, called import_php. i wanted to receive data passed through CURL to use it in a data insertion method.
import_usuario.php fileis
<?php
new Usuario($usuario); // No caso a variável $usuario seria os dados recebidos atraves CURL
Curl is calling the page correctly, because if you print in import_usuario.php it is printed normally
Debt is like receiving data passed through php’s Curl
Maybe this answer help you.
– André Ribeiro
Perfect André, thank you very much.
– tkmtts
André Ribeiro, post your answer as an answer, even if it is the link.
– Shura16