Joomla.it Forum
Non solo Joomla... => Sviluppo => : GAM 01 Feb 2014, 18:50:45
-
Salve,
come da titolo vorrei capire se si può usare questa classe (libraries/joomla/http/factory.php) per
poter inviare richieste HTTP ad un server esterno.
Grazie
-
si ma devi includerla mentre nella 3.0 dovrebbe essere già inclusa
... cmq avevi già aperto una discussione su questo
-
spero possa servire a qualcuno, cmq sono riuscito ad ottenere ciò che mi serviva usando le librerie proprie di joomla per inviare/ricevere dati verso un URL di un sito esterno.
Ecco il codice:
defined('_JEXEC') or die('Restricted access');
jimport( 'joomla.http.factory' );
jimport( 'joomla.http.http' );
jimport( 'joomla.http.response' );
class modHelloWorldHelper
{
public static function getHello( $params )
{
$url = "http://www.sitoditest.it/index.php?prova=xyz";
$http = JHttpFactory::getHttp();
//invio l'URL in post
$resp = $http->post($url);
//siccome il body della response era formattato con XML, ho usato questo metodo per estrarre la stringa
return htmlspecialchars($resp->body);
}
}
Se secondo voi si può migliorare questo codice fatemi sapere.
Grazie