- stream_context_create: documentation ( source)
- stream_get_contents: documentation ( source)
- fopen: documentation ( source)
<?php
$url = 'https://www.tiny.com.br/api2/produtos.pesquisa.php';
$token = '6134695a443b60856faf745793258745e3328a33';
$pesquisa = 'xxxxx';
$data = "token=$token&pesquisa=$pesquisa&formato=XML";
enviarREST($url, $data);
function enviarREST($url, $data, $optional_headers = null) {
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problema com $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problema obtendo retorno de $url, $php_errormsg");
}
return $response;
}