Comunidad de diseño web y desarrollo en internet online

Leer XML alojado en servidor externo

Citar            
MensajeEscrito el 13 May 2010 08:02 am
Hola.

En una página que estoy haciendo tengo un módulo hecho en as3 que lee la predicción del tiempo que da google con mediante un xml (ejemplo: http://www.google.com/ig/api?weather=madrid,spain&hl=es), recoje los datos y los muestra.

En local funciona todo bien pero al subirlo ya no. El problema viene dado porque al parecer flash no deja leer archivos alojados en otros servidores.

¿Alguna sugerencia?

Por juanfher

74 de clabLevel



 

firefox
Citar            
MensajeEscrito el 14 May 2010 05:51 am
¿Nadie sabe como leer un XML alojado en otro servidor?... Por más que busco no doy con la solución.

Por juanfher

74 de clabLevel



 

firefox
Citar            
MensajeEscrito el 14 May 2010 05:58 am
Y para seguir con los rompederos de cabeza. Me he topado con esto: Clase para acceder a Google Weather y lo he usado como un servicio (quitando esto:

Código PHP :

# $gweather = new GoogleWeatherAPI('valencia','es');   
# if($gweather->isFound()) {  
#     echo '<pre>'; print_r($gweather->getCity()); echo '</pre>';  
#     echo '<pre>'; print_r($gweather->getCurrent()); echo '</pre>';  
#     echo '<pre>'; print_r($gweather->getForecast()); echo '</pre>';  
# } 
,claro) para el AMFphp, pero seguimos con lo mismo... al ejecutarlo en local funciona perfecto pero al ejecutarlo en el servidor no hace nada de nada... y no es que lo esté llamando mal o le esté dando mal la ruta del servicio porque los otros servicios que tengo sí que funcionan...

NO LO ENTIEEEEEENDOOOOOO :cry:

Por juanfher

74 de clabLevel



 

firefox
Citar            
MensajeEscrito el 14 May 2010 08:38 am
Es que google no tiene crossdomain. Hay veces que funciona, si tienes php, tener un fichero "xml_proxy.php" con este código

Código :

<?php
 
$post_data = $HTTP_RAW_POST_DATA;

$header[] = "Content-type: text/xml";
$header[] = "Content-length: ".strlen($post_data);

$ch = curl_init( $_GET['url'] ); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

if ( strlen($post_data)>0 ){
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}

$response = curl_exec($ch);     

if (curl_errno($ch)) {
    print curl_error($ch);
} else {
    curl_close($ch);
    print $response;
}
?>

Así, en lugar de preguntar por la dirección http://www.google.com/ig/api?weather=madrid,spain&hl=es
preguntas por la dirección
xmlrpc_proxy.php?url=http://www.google.com/ig/api?weather=madrid,spain&hl=es

NO sé si hay algún modo más sencillo y NO sé si funciona

Por Eliseo2

710 de clabLevel



 

firefox
Citar            
MensajeEscrito el 14 May 2010 08:43 am
Vale, supongo que no se puede. Así que hay que cambiar un poco el php para escribir

Código ActionScript :

xmlrpc_proxy.php?weather=madrid,spain&hl=es

Y tu php será

Código :

<?php
 
$post_data = $HTTP_RAW_POST_DATA;

$header[] = "Content-type: text/xml";
$header[] = "Content-length: ".strlen($post_data);

$ch = curl_init( $_GET['url'] ); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

if ( strlen($post_data)>0 ){
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
$ch="http://www.google.com/ig/api?".$ch;
$response = curl_exec($ch);     

if (curl_errno($ch)) {
    print curl_error($ch);
} else {
    curl_close($ch);
    print $response;
}
?>

Por Eliseo2

710 de clabLevel



 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.