Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/11/2006, 20:01
Bkwxs
 
Fecha de Ingreso: marzo-2005
Mensajes: 171
Antigüedad: 19 años, 2 meses
Puntos: 0
method POST en diferente dominio

Hola, mi pregunta es la siguiente:
Tengo un pequeño formulario que debe interactuar con un archivo php mediante el metodo POST. El archivo php esta en otro servidor. Probe con una solucion que dieron en otro foro de usar un archivo php asi:

Código PHP:
<?
$a
=$_REQUEST["URL"];
echo 
file_get_contents($a);
?>
Pero no me funciono. Tambien probe utilizando un proxy simple en php, pero tampoco funciono.
Cualquiera de estas dos soluciones me permite acceder al archivo php del segundo dominio, pero parece que las variables se pierden en el camino. La pagina ejecuta bien, pero no se que les pasa a las variables que estoy pasando por el formulario porque desaparecen.
Les voy a poner el codigo del formulario y el del proxy

Pagina con el formulario:

Código PHP:
<html>
<
head>
<
title>Paso de variables por metodo GET</title>
</
head>

<
script language="javascript">
function 
crearAjax()
{
    var 
xmlhttp=false;
     try
    {
      
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (
e)
    {
        try
        {
               
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (
E)
        {
               
xmlhttp false;
          }
     }

    if (!
xmlhttp && typeof XMLHttpRequest!='undefined')
    {
          
xmlhttp = new XMLHttpRequest();
    }
    return 
xmlhttp;
}


function 
Contenido()
{
    var 
url;
    var 
t1t2content;



// The web services request minus the domain name
var path '.../ej_ajax.php';

// The full path to the PHP proxy
var url 'http://.../...../proxy.php?yws_path=' encodeURIComponent(path);



    
content document.getElementById('content');
    
    
//Cargar en variables los valores del formulario
    
t1 document.getElementById('aa').value;
    
t2 document.getElementById('11').value;


    
//Crear objeto de AJAX
    
ajax=crearAjax();
   
    
//Enviar información por el metodo POST
ajax.open("POST",url,true);
   
ajax.onreadystatechange=function()
    {
        if (
ajax.readyState==4)
        {
            
content.innerHTML ajax.responseText
        
}
    }
    
ajax.setRequestHeader('Content-Type''application/x-www-form-urlencoded');
    
ajax.send("t1="+t1+"&t2="+t2)
}

window.onload= function()
{   
    
Contenido()
}
</script>

<style type="text/css">
#content{
border: 1px solid #336699;
padding: 10px;
margin: 14px;
}
</style>

<body>



<form onSubmit="Contenido(); return false">
<div><INPUT type=text name=aa value="aaaaa"/></div>
<div><INPUT type=text name=11 value="11111" /> </div>

</form>

DIV donde se muestra la información enviada:
<div id="content"></div>

</body>
</html> 
Pagina con el archivo PHP:

Código PHP:
<?php
echo "Datos enviados por el método POST: <pre>";
print_r($_POST); //Muestra todas la variables POST y sus valores
echo "</pre>";
?>
Pagina del PROXY:

Código PHP:
<?php
// PHP Proxy example for Yahoo! Web services. 
// Responds to both HTTP GET and POST requests
//
// Author: Jason Levitt
// December 7th, 2005
//

// Allowed hostname (api.local and api.travel are also possible here)
define ('HOSTNAME''http://www......com.ar/');

// Get the REST call path from the AJAX application
// Is it a POST or a GET?
$path = ($_POST['yws_path']) ? $_POST['yws_path'] : $_GET['yws_path'];
$url HOSTNAME.$path;

// Open the Curl session
$session curl_init($url);

// If it's a POST, put the POST data in the body
if ($_POST['yws_path']) {
    
$postvars '';
    while (
$element current($_POST)) {
        
$postvars .= key($_POST).'='.$element.'&';
        
next($_POST);
    }
    
curl_setopt ($sessionCURLOPT_POSTtrue);
    
curl_setopt ($sessionCURLOPT_POSTFIELDS$postvars);
}

// Don't return HTTP headers. Do return the contents of the call
curl_setopt($sessionCURLOPT_HEADERfalse);
curl_setopt($sessionCURLOPT_RETURNTRANSFERtrue);

// Make the call
$xml curl_exec($session);

// The web service returns XML. Set the Content-Type appropriately
header("Content-Type: text/xml");

echo 
$xml;
curl_close($session);

?>

Les agradezco cualquier ayuda que me puedan dar
Saludos