PHP - fsockopen

 
Vista:

fsockopen

Publicado por Mauricio (2 intervenciones) el 06/01/2009 19:47:52
Estimados, tengo un tema al usar el fsockopen con el siguiente código:
<?PHP>

$data='<DATAPACKET Version="2.0">'.
'<METADATA>'.
'<FIELDS>'.
'<FIELD attrname="COD_CADENA" fieldtype="i4"/>'.
'<FIELD attrname="COD_FARMACIA" fieldtype="i4"/>'.
'<FIELD attrname="COD_RUBRO" fieldtype="i4"/>'.
'<FIELD attrname="COD_PRODUCTO" fieldtype="i4"/>'.
'<FIELD attrname="COD_PRESENTACION" fieldtype="i4"/>'.
'<FIELD attrname="STOCK_ACTUAL" fieldtype="i4"/>'.
'<FIELD attrname="FECHA_STOCK" fieldtype="dateTime"/>'.
'<FIELD attrname="BAJA" fieldtype="i2"/>'.
'</FIELDS>'.
'<PARAMS LCID="1033"/>'.
'</METADATA>'.
'<ROWDATA>'.
'<ROW COD_CADENA="1" COD_FARMACIA="168" COD_RUBRO="2" COD_PRODUCTO="427" COD_PRESENTACION="98" STOCK_ACTUAL="1" FECHA_STOCK="20080903T10:03:08440" BAJA="0"/>'
'</ROWDATA>'.
'</DATAPACKET>';

$resultado =sendToHost('localhost',80,'post','/servicio.php',$data);

function sendToHost($host,$port,$method,$path,$data,$useragent=0)
{
// Supply a default method of GET if the one passed was empty
if (empty($method)) {
$method = 'GET';
}
$method = strtoupper($method);
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp){
return "$errstr ($errno)<br /> ";
exit;
}
if ($method == 'GET') {
$path .= '?' . $data;
}
$file ="$method $path HTTP/1.1 ";
$file.="Host: $host ";
$file.="Content-type: text/html ";
//$file.="Content-type: application/x-www-form-urlencoded ";
$file.="Content-length: " . strlen($data) . " ";
$file.="Connection: close ";

if ($useragent) {
$file.="User-Agent: MSIE ";
}

if ($method == 'POST') {
$file.=$data;
//echo $file;
}
fwrite($fp, $file);

while (!feof($fp)) {
$buf .= fgets($fp);
}
fclose($fp);
return $buf;
}
?>

ok, espero lo puedan leer bien, te tema es que cuando llega el mensaje que es el xml que preparo en $data, si el Content-type que utilizo es text/html o text/xml, el servidor al que le envió esta info no recibe nada :S, increible pero verdadero, si por el contrario el content-type es application/x-www-form-urlencode entonces el servidor si recibe los datos pero todo lo que va con comillas (") lo substituye por (") jajaj..., ahora bien, trate de mandarle " en vez de las comillas, pero entonces el XML le llega incompleto :(

Alguna idea???

muchas gracias.

Mau
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder