I'm doing a webservice, with no framework, using PHP + JSON, with localhost xampp initially, so I'll put it on some cloud server.
I created in xampp / htdocs two folders, "client" and "provider", in the future 'client' will be on one server and 'provider' on another, where client will be user access sending data through a form via cURL , and the supplier will receive this data and provide information for feedback in the customer interface. For now I am not using database, but soon I will implement, I believe that for this initial mechanism do not need bd.
To process the form data sent by the client, I did the following:
$url = "http://127.0.0.1/ws/fornecedor/wsClientRequire.php";
$cURL = curl_init($url);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
// Definimos um array seguindo o padrão:
// '<name do input>' => '<valor inserido>'
$dados = array(
'nome' => 'John da silva',
'email' => '[email protected]',
'mensagem' => 'Testando o cURL!'
);
// Iremos usar o método POST
curl_setopt($cURL, CURLOPT_POST, true);
// Definimos quais informações serão enviadas pelo POST (array)
curl_setopt($cURL, CURLOPT_POSTFIELDS, $dados);
$resultado = curl_exec($cURL);
$resposta = curl_getinfo($cURL, CURLINFO_HTTP_CODE);
curl_close($cURL);
if ($resposta == '404') {
echo 'O site está fora do ar (ERRO 404)!';
} else {
echo 'Parece que está tudo bem...';
}
//var_dump(json_decode($jsonRet, true)); //com var_dump aparece NULL
$retorno = json_decode($jsonRet);
$success = $retorno->data->success;
echo " \n success: ".$success;
In this section:
$retorno = json_decode($jsonRet);
$success = $retorno->data->success;
echo " \n success: ".$success;
I was hoping to receive the information contained in the vendor's file ... but that did not happen ... So I would like to know how to do this part of the web service configuration. I did so at the vendor:
$success = "Recebido com sucesso.";
$message = null;
$dados = array();
header('Content-Type: application/json; charset=utf-8');
echo json_encode(
array(
'success' => $success,
'message' => $message,
'dados' => $dados
)
);
exit;
The communication between customer and supplier did not occur as desired ... does anyone know how to solve ???
To clarify my question ... in the "provider" which is the last code I posted, how do I read the data that the client sent via cURL? and how do I make a return available, which will be displayed in the client interface? How do I send the headers via cURL in the "client" file, in that headers in cUrl setopt would it be necessary to send a kind of token for access authorization, and how do I read that header token in the vendor file?