Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/11/2009, 17:22
bigwhite
 
Fecha de Ingreso: agosto-2009
Mensajes: 247
Antigüedad: 14 años, 8 meses
Puntos: 10
Exclamación Simular POST: como redirecciono luego?

Hola Amigos: sucede que tengo que parsear una web y basandome el formulario de logueo original y con un script que encontré logro loguearme y ver una pagina del site pero lamentablemente necesito ver OTRA pagina interna.

Cuando intento seguir el enlace...... recibo un error 102 ERR_CONNECTION_REFUSED

Alguna idea de como se soluciona? les paso el script pero para probarlo necesitarian datos de cuenta. Ojala me puedan ayudar!

Código PHP:
<?
// LOGUEO en RAVA

Include "pass.inc.php";

$form_url "http://www.rava.com.ar/v2/clientes/posicion.php?";
$form_method "POST";


// DATOS PERSONALES

$form_data['accion']="u_login";
$form_data['usuario_nivel_acceso']="cliente";
$form_data['u_usuario']=$user;
$form_data['u_clave']=$pass;


// Build the request data string
$request_data "";
foreach (
$form_data as $name=>$value)
{
if (
strlen($request_data) > 0)
$request_data .= '&';
$request_data .= $name.'='.urlencode($value);
}

// Build the request
$url parse_url($form_url);
$form_method strtoupper($form_method);
$request $form_method." ";
switch (
$form_method)
{
case 
'GET':
$request .= $url['path']."?".$request_data." HTTP/1.1\r\nHost: ".$url['host']."\r\n\r\n";
break;
case 
'POST':
$request .= $url['path'] ." HTTP/1.1\r\nHost: ".$url['host']."\r\nContent-type: application/x-www-form-urlencoded\r\nContent-length: ".strlen($request_data)."\r\n\r\n".$request_data;
break;
default:die(
"Invalid method: ".$form_method);
}

$fp fsockopen($url['host'], 80$err_num$err_msg30);
if (
$fp)
{
fputs($fp$request);
while (!
feof($fp))
$response .= fgets($fp128);
$header_end=strpos($response,'<!DOCTYPE HTML PUBLIC');
$header=substr($response,0,$header_end);
$headers=explode('\n\r',$header);
for (
$i=0;$i<sizeof($headers);$i++)
header($headers[$i]);
$response=substr($response,$header_end);
$response=str_replace('href="/','href="https://'.$url['host'].'/',$response);
$response=str_replace('src="/','src="https://'.$url['host'].'/',$response);
$response=str_replace('src=\"/','src=\"https://'.$url['host'].'/',$response);
$response=str_replace('background="/','background="https://'.$url['host'].'/',$response);

echo 
$response;
fclose($fp);
}
else
{
echo 
'Could not connect to: '.htmlentities($url['host']).'<br />';
echo 
'Error #'.$err_num.': '.$err_msg;
exit;
}

?>
y aca el error cuando intento navegar despues de loguear:

Cita:
Error 102 (net::ERR_CONNECTION_REFUSED): Error desconocido
He intentado no cerrando el socket comentando la sentencia fclose($fp); pero sin resultados

Última edición por bigwhite; 12/11/2009 a las 17:30